rodrigomasini commited on
Commit
8683afa
·
verified ·
1 Parent(s): 17a80d5

Update alternative-2.py

Browse files
Files changed (1) hide show
  1. alternative-2.py +11 -12
alternative-2.py CHANGED
@@ -97,7 +97,7 @@ def extractDataFromUrls(urls: str, loader_type: str):
97
  for item in data:
98
  jsonData.append(item.to_json())
99
 
100
- return jsonData, data
101
 
102
  except Exception as err:
103
  return "An Error Occurred. Contact Developer" + str(err), "Error Occured. Boom"
@@ -140,27 +140,26 @@ choices = [
140
 
141
  # Create the Gradio interface
142
  with gr.Blocks(theme="sudeepshouche/minimalist") as demo:
 
 
143
  gr.Markdown("# The Big Scraper")
144
  with gr.Tab("Scraped"):
145
  with gr.Row():
146
- url_input = gr.Textbox(label="Enter your comma separated URLs here")
147
- loader_dropdown = gr.Dropdown(choices=choices, label="Pick your Loader from here")
148
- with gr.Row():
149
- json_output = gr.JSON(label="Extracted Data (JSON)")
150
- text_output = gr.Textbox(label="Extracted Data (Text)")
 
151
 
152
  btn = gr.Button("Extract Data")
153
- btn.click(extractDataFromUrls, inputs=[url_input, loader_dropdown], outputs=[json_output, text_output])
 
154
 
155
  with gr.Tab("Images"):
156
- with gr.Row():
157
- image_url_input = gr.Textbox(label="Enter URL for Screenshot:")
158
  with gr.Row():
159
  screenshot_output = gr.Image(label="Screenshot")
160
  title_output = gr.Textbox(label="Page Title")
161
 
162
- btn2 = gr.Button("Take Screenshot")
163
- btn2.click(take_webdata, inputs=image_url_input, outputs=[screenshot_output, title_output])
164
-
165
  # Launch the Gradio interface
166
  demo.launch()
 
97
  for item in data:
98
  jsonData.append(item.to_json())
99
 
100
+ return jsonData, data, urls[0]
101
 
102
  except Exception as err:
103
  return "An Error Occurred. Contact Developer" + str(err), "Error Occured. Boom"
 
140
 
141
  # Create the Gradio interface
142
  with gr.Blocks(theme="sudeepshouche/minimalist") as demo:
143
+ extracted_url = gr.State() # Use gr.State() to store the URL
144
+
145
  gr.Markdown("# The Big Scraper")
146
  with gr.Tab("Scraped"):
147
  with gr.Row():
148
+ with gr.Column():
149
+ url_input = gr.Textbox(label="Enter your comma separated URLs here")
150
+ loader_dropdown = gr.Dropdown(choices=choices, label="Pick your Loader from here")
151
+ with gr.Column():
152
+ json_output = gr.JSON(label="Extracted Data (JSON)")
153
+ text_output = gr.Textbox(label="Extracted Data (Text)")
154
 
155
  btn = gr.Button("Extract Data")
156
+ btn.click(extractDataFromUrls, inputs=[url_input, loader_dropdown], outputs=[json_output, text_output, extracted_url]) \
157
+ .then(take_webdata, inputs=extracted_url, outputs=[screenshot_output, title_output])
158
 
159
  with gr.Tab("Images"):
 
 
160
  with gr.Row():
161
  screenshot_output = gr.Image(label="Screenshot")
162
  title_output = gr.Textbox(label="Page Title")
163
 
 
 
 
164
  # Launch the Gradio interface
165
  demo.launch()