|
import gradio as gr |
|
import requests |
|
from PIL import Image |
|
import io |
|
|
|
|
|
FASTAPI_URL = "https://fiamenova-aap.hf.space/predict/" |
|
|
|
def predict_image(image: Image.Image): |
|
|
|
byte_array = io.BytesIO() |
|
image.save(byte_array, format="PNG") |
|
byte_array = byte_array.getvalue() |
|
|
|
|
|
response = requests.post(FASTAPI_URL, files={"image": byte_array}) |
|
|
|
if response.status_code == 200: |
|
return response.json()["prediction"] |
|
else: |
|
return f"Error: {response.text}" |
|
|
|
|
|
iface = gr.Interface(fn=predict_image, |
|
inputs=gr.Image(type="pil"), |
|
outputs="text") |
|
|
|
|
|
iface.launch() |