Spaces:
Runtime error
Runtime error
Srinivasulu kethanaboina commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,25 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
app = FastAPI()
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|