foodformer-demo / app.py
wei12138's picture
Update app.py
d384407
raw
history blame
1.15 kB
from flask import Flask
from flask_httpauth import HTTPBasicAuth
import requests
import gradio as gr
app = Flask(__name__)
auth = HTTPBasicAuth()
users = {
"wei": "123", # You can add more users and passwords here
}
@auth.get_password
def get_pw(username):
if username in users:
return users.get(username)
return None
@app.route('/')
@auth.login_required
def index():
def classify_image(filepath):
"""
Function to send image to the FastAPI server for classification
and then return the results.
"""
print("============")
url = "http://18.220.25.54/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='upload',label="Upload Image or Capture from Webcam"
,type="filepath"),
outputs=gr.Label(num_top_classes=3, label="Predicted Class")
)
return oi.launch()
if __name__ == "__main__":
app.run()