Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
outputs="image",
|
| 12 |
-
title="
|
| 13 |
-
description="Upload an image
|
| 14 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from inference_sdk import InferenceHTTPClient
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import requests
|
| 5 |
|
| 6 |
+
# Initialize the Roboflow client
|
| 7 |
+
client = InferenceHTTPClient(
|
| 8 |
+
api_url="https://detect.roboflow.com",
|
| 9 |
+
api_key="dxkgGGHSZ3DI8XzVn29U"
|
| 10 |
+
)
|
| 11 |
|
| 12 |
+
# Prediction function
|
| 13 |
+
def predict(image: Image.Image):
|
| 14 |
+
# Convert PIL image to bytes
|
| 15 |
+
image.save("temp.jpg") # Save locally for upload
|
| 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 |
+
# Get the annotated image URL from the result
|
| 25 |
+
annotated_url = result.get("visualizations", {}).get("image")
|
| 26 |
+
if annotated_url:
|
| 27 |
+
response = requests.get(annotated_url, stream=True)
|
| 28 |
+
return Image.open(response.raw)
|
| 29 |
+
else:
|
| 30 |
+
return "No annotated image returned."
|
| 31 |
+
|
| 32 |
+
# Gradio UI
|
| 33 |
+
demo = gr.Interface(
|
| 34 |
+
fn=predict,
|
| 35 |
+
inputs=gr.Image(type="pil"),
|
| 36 |
outputs="image",
|
| 37 |
+
title="Solar Panel Fault Detection",
|
| 38 |
+
description="Upload an image and get predictions from your Roboflow workflow."
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
demo.launch()
|
| 42 |
+
|