abhishekjoel commited on
Commit
ce9f2e2
·
verified ·
1 Parent(s): 401927c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -6,7 +6,7 @@ from pydantic import BaseModel
6
  import gradio as gr
7
  import uvicorn
8
 
9
- # FastAPI app setup
10
  app = FastAPI()
11
 
12
  class Numbers(BaseModel):
@@ -43,15 +43,15 @@ def multiply_numbers(x: float, y: float) -> float:
43
  def divide_numbers(x: float, y: float) -> float:
44
  return x / y
45
 
46
- # Function to run the FastAPI app
47
  def run_fastapi():
48
  uvicorn.run(app, host="127.0.0.1", port=8000)
49
 
50
- # Start the FastAPI server in a separate thread
51
  thread = threading.Thread(target=run_fastapi, daemon=True)
52
  thread.start()
53
 
54
- # Gradio frontend setup
55
  BASE_URL = "http://127.0.0.1:8000"
56
 
57
  def perform_operation(operation: str, x: float, y: float) -> str:
@@ -64,7 +64,7 @@ def perform_operation(operation: str, x: float, y: float) -> str:
64
  except requests.exceptions.HTTPError as err:
65
  return f"Error: {err.response.json().get('detail')}"
66
 
67
- # Gradio interface
68
  iface = gr.Interface(
69
  fn=perform_operation,
70
  inputs=[
@@ -76,6 +76,6 @@ iface = gr.Interface(
76
  live=False
77
  )
78
 
79
- # Wait a moment to ensure the server is up before launching Gradio
80
  time.sleep(1)
81
  iface.launch()
 
6
  import gradio as gr
7
  import uvicorn
8
 
9
+
10
  app = FastAPI()
11
 
12
  class Numbers(BaseModel):
 
43
  def divide_numbers(x: float, y: float) -> float:
44
  return x / y
45
 
46
+
47
  def run_fastapi():
48
  uvicorn.run(app, host="127.0.0.1", port=8000)
49
 
50
+
51
  thread = threading.Thread(target=run_fastapi, daemon=True)
52
  thread.start()
53
 
54
+
55
  BASE_URL = "http://127.0.0.1:8000"
56
 
57
  def perform_operation(operation: str, x: float, y: float) -> str:
 
64
  except requests.exceptions.HTTPError as err:
65
  return f"Error: {err.response.json().get('detail')}"
66
 
67
+
68
  iface = gr.Interface(
69
  fn=perform_operation,
70
  inputs=[
 
76
  live=False
77
  )
78
 
79
+
80
  time.sleep(1)
81
  iface.launch()