Srinivasulu kethanaboina commited on
Commit
4a1be1e
1 Parent(s): af359e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -1,8 +1,25 @@
1
- from fastapi import FastAPI
2
  import gradio as gr
 
 
 
 
 
3
  app = FastAPI()
4
- @app.get("/")
5
- def echo(message, history):
6
- return message
7
- io = gr.ChatInterface(echo)
8
- app = gr.mount_gradio_app(app, io, path="/gradio")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from fastapi import FastAPI
3
+ from fastapi.staticfiles import StaticFiles
4
+ import uvicorn
5
+
6
+ # Initialize FastAPI app
7
  app = FastAPI()
8
+
9
+ # Define a function for the chat interface
10
+ def respond_to_chat(history, message):
11
+ response = f"Hello, {message}!"
12
+ return response, history
13
+
14
+ # Create Gradio ChatInterface
15
+ chat = gr.ChatInterface(fn=respond_to_chat, title="Chat with AI")
16
+
17
+ # Mount static files
18
+ app.mount("/static", StaticFiles(directory="static", html=True), name="static")
19
+
20
+ # Mount Gradio ChatInterface to FastAPI app
21
+ app = gr.mount_gradio_app(app, chat, "/", gradio_api_url="http://localhost:7860/")
22
+
23
+ # Run the app with uvicorn
24
+ if __name__ == "__main__":
25
+ uvicorn.run(app, host="0.0.0.0", port=7860)