NaveenKumar5 commited on
Commit
953da67
·
verified ·
1 Parent(s): 55cf9cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -10
app.py CHANGED
@@ -1,14 +1,42 @@
1
  import gradio as gr
2
- from roboflow_model import predict_image
 
 
3
 
4
- def infer(image):
5
- output = predict_image(image)
6
- return output # Gradio automatically handles NumPy images
 
 
7
 
8
- gr.Interface(
9
- fn=infer,
10
- inputs=gr.Image(type="filepath"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  outputs="image",
12
- title="Roboflow Fault Detector",
13
- description="Upload an image to detect faults using Roboflow workflow."
14
- ).launch()
 
 
 
 
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
+