abhishekjoel commited on
Commit
693f784
·
verified ·
1 Parent(s): c54bb80

Create gradio_interface.py

Browse files
Files changed (1) hide show
  1. gradio_interface.py +25 -0
gradio_interface.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # Base URL of your FastAPI app
5
+ BASE_URL = "http://localhost:8000" # Use the correct URL for deployment
6
+
7
+ def perform_operation(operation: str, x: float, y: float) -> float:
8
+ url = f"{BASE_URL}/{operation}"
9
+ response = requests.post(url, json={"x": x, "y": y})
10
+ result = response.json().get("result")
11
+ return result
12
+
13
+ # Create Gradio interface
14
+ iface = gr.Interface(
15
+ fn=perform_operation,
16
+ inputs=[
17
+ gr.Radio(choices=["add", "subtract", "multiply", "divide"], label="Operation"),
18
+ gr.Number(label="X"),
19
+ gr.Number(label="Y")
20
+ ],
21
+ outputs="text",
22
+ live=True
23
+ )
24
+
25
+ iface.launch()