wei12138 commited on
Commit
8534bf9
β€’
1 Parent(s): 4f5db05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -7
app.py CHANGED
@@ -1,8 +1,28 @@
1
- from fastapi import FastAPI
2
  import gradio as gr
3
- app = FastAPI()
4
- @app.get("/")
5
- def read_main():
6
- return {"message": "This is your main app"}
7
- io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
8
- app = gr.mount_gradio_app(app, io, path="/gradio")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.191.206.114/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.Label(num_top_classes=3, label="Predicted Class"),
26
+ )
27
+
28
+ oi.launch()