Spaces:
Sleeping
Sleeping
Commit ·
78ee187
1
Parent(s): fb28bb9
gradio
Browse files- app.py +26 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
API_URL = "https://TU-API-EN-RENDER.onrender.com/predict"
|
| 5 |
+
|
| 6 |
+
def obtain_pred():
|
| 7 |
+
try:
|
| 8 |
+
response = requests.get(API_URL, timeout=10)
|
| 9 |
+
if response.status_code == 200:
|
| 10 |
+
data = response.json()
|
| 11 |
+
return f"Predicted label: {data.get('label', 'No label field found')}"
|
| 12 |
+
else:
|
| 13 |
+
return f"Error: API returned status {response.status_code}"
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"Error contacting API: {e}"
|
| 16 |
+
|
| 17 |
+
demo = gr.Interface(
|
| 18 |
+
fn=obtain_pred,
|
| 19 |
+
inputs=[],
|
| 20 |
+
outputs="text",
|
| 21 |
+
title="Random Prediction Demo",
|
| 22 |
+
description="This app calls the API hosted on Render to obtain a random prediction."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
requests
|