Ahmed007 commited on
Commit
b86c308
·
1 Parent(s): 40df25a

Add application file

Browse files
Files changed (2) hide show
  1. app.py +9 -2
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,10 +1,17 @@
 
 
1
  import gradio as gr
2
  import requests
 
3
 
4
  def send_to_fastapi(image, question):
5
  url = 'https://ahmed007-modarb-api.hf.space/analyze-image/'
6
- # Convert the image to bytes for the request
7
- image_bytes = image.read()
 
 
 
 
8
  files = {'file': ('image.png', image_bytes, 'image/png')}
9
  data = {'question': question}
10
  response = requests.post(url, files=files, data=data)
 
1
+ import cv2
2
+ import numpy as np
3
  import gradio as gr
4
  import requests
5
+ from io import BytesIO
6
 
7
  def send_to_fastapi(image, question):
8
  url = 'https://ahmed007-modarb-api.hf.space/analyze-image/'
9
+
10
+
11
+ # Convert the numpy image to bytes
12
+ _, encoded_image = cv2.imencode('.png', image)
13
+ image_bytes = BytesIO(encoded_image.tobytes())
14
+
15
  files = {'file': ('image.png', image_bytes, 'image/png')}
16
  data = {'question': question}
17
  response = requests.post(url, files=files, data=data)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ opencv-python-headless