Spaces:
Sleeping
Sleeping
File size: 871 Bytes
b86c308 6e0e2bc b86c308 6e0e2bc 40df25a b86c308 40df25a 6e0e2bc 40df25a 6e0e2bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import cv2
import numpy as np
import gradio as gr
import requests
from io import BytesIO
def send_to_fastapi(image, question):
url = 'https://ahmed007-modarb-api.hf.space/analyze-image/'
# Convert the numpy image to bytes
_, encoded_image = cv2.imencode('.png', image)
image_bytes = BytesIO(encoded_image.tobytes())
files = {'file': ('image.png', image_bytes, 'image/png')}
data = {'question': question}
response = requests.post(url, files=files, data=data)
return response.json()['answer']
iface = gr.Interface(fn=send_to_fastapi,
inputs=[gr.Image(), gr.Textbox(lines=2, placeholder="Enter your question here...")],
outputs='text',
title="Image Question Answering",
description="Upload an image and ask a question about it.")
iface.launch() |