Dilip8756 commited on
Commit
4c3f949
·
verified ·
1 Parent(s): 930d8d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -1,22 +1,32 @@
1
  import gradio as gr
2
  from handler import EndpointHandler
3
- import os
4
 
5
  # Model loading
6
  handler = EndpointHandler(".")
7
 
8
  def predict(image):
9
  try:
10
- # Image input ko handler me bhejna
11
- result = handler({"inputs": image})
12
- return result["prediction"]
 
 
 
 
 
 
 
 
 
 
13
  except Exception as e:
14
- return str(e)
15
 
16
- # Gradio Interface (API provide karega)
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
  )