COLTO50 commited on
Commit
afd3cf6
·
verified ·
1 Parent(s): 8fb6e99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -1,7 +1,3 @@
1
- pip install gradio requests
2
-
3
- # Create the Gradio application
4
- cat > app.py << EOL
5
  import gradio as gr
6
  import requests
7
  import concurrent.futures
@@ -9,28 +5,28 @@ import concurrent.futures
9
  def open_links(link, count):
10
  def open_link(url):
11
  try:
12
- response = requests.get(url)
13
- return response.status_code
14
- except:
15
- return 'Error'
16
 
17
  results = []
18
  with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
19
  futures = [executor.submit(open_link, link) for _ in range(count)]
20
  for future in concurrent.futures.as_completed(futures):
21
- results.append(str(future.result()))
22
 
23
  return "\n".join(results)
24
 
25
  iface = gr.Interface(
26
  fn=open_links,
27
  inputs=[
28
- gr.Textbox(label="Enter link"),
29
- gr.Slider(minimum=1, maximum=100, step=1, label="Number of times to open")
30
  ],
31
- outputs="text",
32
  title="Link Opener",
33
- description="Enter a link and choose how many times to open it.",
34
  theme="huggingface",
35
  examples=[["https://www.example.com", 5]]
36
  )
 
 
 
 
 
1
  import gradio as gr
2
  import requests
3
  import concurrent.futures
 
5
  def open_links(link, count):
6
  def open_link(url):
7
  try:
8
+ response = requests.get(url, timeout=10)
9
+ return f"Status: {response.status_code}"
10
+ except requests.exceptions.RequestException as e:
11
+ return f"Error: {str(e)}"
12
 
13
  results = []
14
  with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
15
  futures = [executor.submit(open_link, link) for _ in range(count)]
16
  for future in concurrent.futures.as_completed(futures):
17
+ results.append(future.result())
18
 
19
  return "\n".join(results)
20
 
21
  iface = gr.Interface(
22
  fn=open_links,
23
  inputs=[
24
+ gr.Textbox(label="Enter link", placeholder="https://example.com"),
25
+ gr.Slider(minimum=1, maximum=50, step=1, value=5, label="Number of times to open")
26
  ],
27
+ outputs=gr.Textbox(label="Results"),
28
  title="Link Opener",
29
+ description="Enter a link and choose how many times to open it. The app will attempt to open the link and return the status for each attempt.",
30
  theme="huggingface",
31
  examples=[["https://www.example.com", 5]]
32
  )