AAPFront / app.py
FIamenova's picture
Update app.py
79695a4 verified
raw
history blame contribute delete
877 Bytes
import gradio as gr
import requests
from PIL import Image
import io
# URL for FastAPI backend (ensure to replace with your actual FastAPI URL)
FASTAPI_URL = "https://fiamenova-aap.hf.space/predict/"
def predict_image(image: Image.Image):
# Convert PIL image to bytes
byte_array = io.BytesIO()
image.save(byte_array, format="PNG")
byte_array = byte_array.getvalue()
# Send the image to FastAPI service for prediction
response = requests.post(FASTAPI_URL, files={"image": byte_array}) # Change 'file' to 'image'
if response.status_code == 200:
return response.json()["prediction"]
else:
return f"Error: {response.text}"
# Create Gradio interface
iface = gr.Interface(fn=predict_image,
inputs=gr.Image(type="pil"),
outputs="text")
# Launch the Gradio interface
iface.launch()