File size: 877 Bytes
0f60e23
 
 
 
 
 
f3438e0
0f60e23
 
 
 
 
 
 
 
79695a4
0f60e23
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
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()