File size: 664 Bytes
910fdf0
 
 
 
 
 
 
 
 
 
 
 
6dc2b75
910fdf0
 
 
 
 
 
 
 
 
976c1c1
910fdf0
6a177ee
910fdf0
 
 
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
import requests
import gradio as gr




def classify_image(filepath):
    """
    Function to send image to the FastAPI server for classification
    and then return the results.
    """
    print("============")
    url = "http://18.191.206.114/predict"
    with open(filepath, "rb") as f:
        response = requests.post(url, files={"file": f})
    print('成功')
    return response.json()['predictions']


oi = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(
        shape=(224, 224), source='webcam',label="Upload Image or Capture from Webcam"
    ,type="filepath"),
    outputs=gr.Label(num_top_classes=3, label="Predicted Class"),
)

oi.launch()