Omnibus commited on
Commit
3b17cd9
·
1 Parent(s): 9ed1189

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -8
app.py CHANGED
@@ -1,8 +1,47 @@
1
- from twitter_scraper_selenium import scrape_profile
2
-
3
- twitter_username = "TwitterAPI"
4
- filename = "twitter_api_data"
5
- browser = "chrome"
6
- headless = True
7
- #print(scrape_profile(twitter_username=twitter_username, filename=filename, browser=browser, headless=headless))
8
- print(scrape_profile(twitter_username="microsoft",output_format="json",browser="chrome",tweets_count=10))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #from __future__ import annotations
2
+ from selenium import webdriver
3
+ #from typing import Iterable
4
+
5
+ import gradio as gr
6
+
7
+ import re
8
+ from PIL import Image
9
+ from io import BytesIO
10
+ from selenium.common.exceptions import WebDriverException
11
+
12
+ driver_type = 'chromedriver'
13
+
14
+ def run_script(text: str):
15
+ regex = r"^(https?://)"
16
+ is_url = re.search(regex, text)
17
+
18
+ if is_url:
19
+ options = webdriver.ChromeOptions()
20
+ options.add_argument('--headless')
21
+ options.add_argument('--no-sandbox')
22
+ options.add_argument('--disable-dev-shm-usage')
23
+
24
+ try:
25
+ driver = webdriver.Chrome(options=options)
26
+ driver.get(text)
27
+ driver.implicitly_wait(30)
28
+ driver.set_window_size(1920, 1080)
29
+ screenshot = driver.get_screenshot_as_png()
30
+ except WebDriverException as e:
31
+ return [Image.new('RGB', (1, 1)), 'operation failed.']
32
+ finally:
33
+ if driver:
34
+ driver.quit()
35
+
36
+ return [Image.open(BytesIO(screenshot)), 'operation success.']
37
+ else:
38
+ return [None, 'Please enter a valid URL of a website/host.']
39
+
40
+ with gr.Blocks() as app:
41
+ inp = gr.Textbox()
42
+ btn= gr.Button()
43
+ with gr.Row():
44
+ outim = gr.Image()
45
+ outp = gr.Textbox()
46
+ btn.click(run_script,inp,[outim,outp])
47
+ app.launch()