Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,25 +9,31 @@ client = InferenceHTTPClient(
|
|
| 9 |
api_key="dxkgGGHSZ3DI8XzVn29U"
|
| 10 |
)
|
| 11 |
|
| 12 |
-
# Prediction function
|
| 13 |
def predict(image: Image.Image):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
response = requests.get(annotated_url, stream=True)
|
|
|
|
|
|
|
|
|
|
| 28 |
return Image.open(response.raw)
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
# Gradio UI
|
| 33 |
demo = gr.Interface(
|
|
|
|
| 9 |
api_key="dxkgGGHSZ3DI8XzVn29U"
|
| 10 |
)
|
| 11 |
|
|
|
|
| 12 |
def predict(image: Image.Image):
|
| 13 |
+
try:
|
| 14 |
+
# Save image temporarily
|
| 15 |
+
image.save("temp.jpg")
|
| 16 |
+
with open("temp.jpg", "rb") as f:
|
| 17 |
+
result = client.run_workflow(
|
| 18 |
+
workspace_name="naveen-kumar-hnmil",
|
| 19 |
+
workflow_id="detect-count-and-visualize-5",
|
| 20 |
+
images={"image": f},
|
| 21 |
+
use_cache=True
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Extract annotated image
|
| 25 |
+
annotated_url = result.get("visualizations", {}).get("image")
|
| 26 |
+
if not annotated_url:
|
| 27 |
+
return "Error: No visualization returned from Roboflow."
|
| 28 |
+
|
| 29 |
response = requests.get(annotated_url, stream=True)
|
| 30 |
+
if response.status_code != 200:
|
| 31 |
+
return f"Error fetching image from: {annotated_url}"
|
| 32 |
+
|
| 33 |
return Image.open(response.raw)
|
| 34 |
+
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Exception: {str(e)}"
|
| 37 |
|
| 38 |
# Gradio UI
|
| 39 |
demo = gr.Interface(
|