Spaces:
Runtime error
Runtime error
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 | |
} | |
def get_pw(username): | |
if username in users: | |
return users.get(username) | |
return None | |
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() |