Upload 3 files
Browse files- README.md +13 -12
- app.py +68 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
-
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: test smolagents
|
| 3 |
+
emoji: 🙄
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
| 5 |
+
|
| 6 |
+
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def check_internet(url="https://www.google.com"):
|
| 10 |
+
try:
|
| 11 |
+
response = requests.get(url, timeout=5)
|
| 12 |
+
if response.status_code == 200:
|
| 13 |
+
print("Internet is working. Status code:", response.status_code)
|
| 14 |
+
else:
|
| 15 |
+
print("Connected to the internet, but the server returned an error. Status code:", response.status_code)
|
| 16 |
+
except requests.ConnectionError:
|
| 17 |
+
print("No internet connection.")
|
| 18 |
+
except requests.Timeout:
|
| 19 |
+
print("Request timed out.")
|
| 20 |
+
except Exception as e:
|
| 21 |
+
print(f"An error occurred: {e}")
|
| 22 |
+
|
| 23 |
+
def check_promptlayer(url="https://api.promptlayer.com/ping"):
|
| 24 |
+
try:
|
| 25 |
+
response = requests.get(url, timeout=5)
|
| 26 |
+
if response.status_code == 200:
|
| 27 |
+
print("Promptlayer is working. Status code:", response.status_code)
|
| 28 |
+
else:
|
| 29 |
+
print("Connected to the Promptlayer, but the server returned an error. Status code:", response.status_code)
|
| 30 |
+
except requests.ConnectionError:
|
| 31 |
+
print("No Promptlayer connection.")
|
| 32 |
+
except requests.Timeout:
|
| 33 |
+
print("Request timed out.")
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"An error occurred: {e}")
|
| 36 |
+
|
| 37 |
+
def check_promptlayer_gr(url="https://api.promptlayer.com/ping"):
|
| 38 |
+
try:
|
| 39 |
+
response = requests.get(url, timeout=30)
|
| 40 |
+
if response.status_code == 200:
|
| 41 |
+
print(f"{url} is working. Status code:", response.status_code)
|
| 42 |
+
gr.Info(f"{url} is working. Status code: {response.status_code}")
|
| 43 |
+
else:
|
| 44 |
+
print(f"Connected to {url}, but the server returned an error. Status code:", response.status_code)
|
| 45 |
+
gr.Info(f"Connected to {url}, but the server returned an error. Status code: {response.status_code}")
|
| 46 |
+
except requests.ConnectionError:
|
| 47 |
+
print("No connection.")
|
| 48 |
+
gr.Info("No connection.")
|
| 49 |
+
except requests.Timeout:
|
| 50 |
+
print("Request timed out.")
|
| 51 |
+
gr.Info("Request timed out.")
|
| 52 |
+
except Exception as e:
|
| 53 |
+
print(f"An error occurred: {e}")
|
| 54 |
+
gr.Info(f"An error occurred: {e}")
|
| 55 |
+
|
| 56 |
+
@spaces.GPU
|
| 57 |
+
def test(s: str):
|
| 58 |
+
ret = agent.run(s)
|
| 59 |
+
return ret
|
| 60 |
+
|
| 61 |
+
with gr.Blocks() as demo:
|
| 62 |
+
input = gr.Textbox(label="Input", value="How many seconds would it take for a leopard at full speed to run through Pont des Arts?")
|
| 63 |
+
run_button = gr.Button("Submit", variant="primary")
|
| 64 |
+
info_md = gr.Markdown("<br><br><br>")
|
| 65 |
+
|
| 66 |
+
run_button.click(test, [input], [info_md])
|
| 67 |
+
|
| 68 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub
|
| 2 |
+
smolagents
|