Spaces:
Runtime error
Runtime error
Download app.py from redfernstech/gradio-fastapi-static: direct link, hf CLI and curl.
- Browser
- Download file 726 Bytes
-
https://huggingface.co/spaces/redfernstech/gradio-fastapi-static/resolve/main/app.py
- Command line
-
hf download hf://spaces/redfernstech/gradio-fastapi-static/app.py
-
curl -L -o app.py https://huggingface.co/spaces/redfernstech/gradio-fastapi-static/resolve/main/app.py
726 Bytes
| import gradio as gr | |
| from fastapi import FastAPI | |
| from fastapi.staticfiles import StaticFiles | |
| import uvicorn | |
| # Initialize FastAPI app | |
| app = FastAPI() | |
| # Define a function for the chat interface | |
| def respond_to_chat(history, message): | |
| response = f"Hello, {message}!" | |
| return response, history | |
| # Create Gradio ChatInterface | |
| chat = gr.ChatInterface(fn=respond_to_chat, title="Chat with AI") | |
| # Mount static files | |
| app.mount("/static", StaticFiles(directory="static", html=True), name="static") | |
| # Mount Gradio ChatInterface to FastAPI app | |
| app = gr.mount_gradio_app(app, chat, "/", gradio_api_url="http://localhost:7860/") | |
| # Run the app with uvicorn | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |