wei12138 commited on
Commit
910fdf0
1 Parent(s): 575850f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+
4
+
5
+
6
+
7
+ def classify_image(filepath):
8
+ """
9
+ Function to send image to the FastAPI server for classification
10
+ and then return the results.
11
+ """
12
+ print("============")
13
+ url = "http://18.220.25.54/predict"
14
+ with open(filepath, "rb") as f:
15
+ response = requests.post(url, files={"file": f})
16
+ print('成功')
17
+ return response.json()['predictions']
18
+
19
+
20
+ oi = gr.Interface(
21
+ fn=classify_image,
22
+ inputs=gr.Image(
23
+ shape=(224, 224), source='upload',label="Upload Image or Capture from Webcam"
24
+ ,type="filepath"),
25
+ outputs=gr.Json(label="Predicted Results"),
26
+ )
27
+
28
+ oi.launch()