Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from handler import EndpointHandler
|
| 3 |
-
import
|
| 4 |
|
| 5 |
# Model loading
|
| 6 |
handler = EndpointHandler(".")
|
| 7 |
|
| 8 |
def predict(image):
|
| 9 |
try:
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
except Exception as e:
|
| 14 |
-
return str(e)
|
| 15 |
|
| 16 |
-
#
|
| 17 |
demo = gr.Interface(
|
| 18 |
fn=predict,
|
| 19 |
-
inputs=gr.Image(type="pil"),
|
| 20 |
outputs="text",
|
| 21 |
title="Master Brain API"
|
| 22 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from handler import EndpointHandler
|
| 3 |
+
import io
|
| 4 |
|
| 5 |
# Model loading
|
| 6 |
handler = EndpointHandler(".")
|
| 7 |
|
| 8 |
def predict(image):
|
| 9 |
try:
|
| 10 |
+
# 1. PIL Image ko Bytes me convert karein
|
| 11 |
+
buf = io.BytesIO()
|
| 12 |
+
image.save(buf, format='PNG')
|
| 13 |
+
image_bytes = buf.getvalue()
|
| 14 |
+
|
| 15 |
+
# 2. Bytes ko handler me bhejna (Jaise apka local code chahta hai)
|
| 16 |
+
result = handler(image_bytes)
|
| 17 |
+
|
| 18 |
+
# Agar result dictionary hai toh prediction key lo, varna direct return
|
| 19 |
+
if isinstance(result, dict):
|
| 20 |
+
return result.get("prediction", "No Prediction")
|
| 21 |
+
return str(result)
|
| 22 |
+
|
| 23 |
except Exception as e:
|
| 24 |
+
return f"Error: {str(e)}"
|
| 25 |
|
| 26 |
+
# Interface
|
| 27 |
demo = gr.Interface(
|
| 28 |
fn=predict,
|
| 29 |
+
inputs=gr.Image(type="pil"), # Gradio PIL image deta hai
|
| 30 |
outputs="text",
|
| 31 |
title="Master Brain API"
|
| 32 |
)
|