Spaces:
Sleeping
Sleeping
Update app.py
Browse files123427 unmodified lines323334353637383940414243444514 unmodified lines60616263import gradio as grfrom fastapi import FastAPI, HTTPExceptionfrom pydantic import BaseModelimport uvicorn27 unmodified linesreturn {"result": numbers.x / numbers.y}# Define the Gradio interface functiondef perform_operation(operation: str, x: float, y: float) -> float:# Construct the URL with the correct scheme and hosturl = f"http://127.0.0.1:8000/{operation}"response = requests.post(url, json={"x": x, "y": y})if response.status_code == 200:return response.json().get("result")else:return f"Error: {response.json().get('detail', 'Unknown error')}"# Define the Gradio interfacedemo = gr.Interface(14 unmodified lines# Run the FastAPI app with Uvicornif __name__ == "__main__":uvicorn.run(app, host="0.0.0.0", port=8000)1234527 unmodified lines3334353637383940414243444546474814 unmodified lines636465import gradio as grfrom fastapi import FastAPI, HTTPExceptionfrom pydantic import BaseModelimport uvicorn27 unmodified linesreturn {"result": numbers.x / numbers.y}# Define the Gradio interface functiondef perform_operation(operation: str, x: float, y: float) -> str:# Construct the URL with the correct scheme and hosturl = f"http://127.0.0.1:8000/{operation}"try:response = requests.post(url, json={"x": x, "y": y})response.raise_for_status() # Raise an error for bad responsesresult = response.json().get("result")return str(result) if result is not None else "Error: Invalid response"except requests.exceptions.RequestException as e:return f"Error: {e}"# Define the Gradio interfacedemo = gr.Interface(14 unmodified lines# Run the FastAPI app with Uvicornif __name__ == "__main__":uvicorn.run(app, host="0.0.0.0", port=8000)
app.py+10-8