Spaces:
Runtime error
Runtime error
import gradio as gr | |
from fastapi import FastAPI, Request, HTTPException | |
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, path="/gradio") | |
# Define the webhook endpoint | |
async def webhook(request: Request): | |
data = await request.json() | |
username = data.get("username") | |
password = data.get("password") | |
if username == "your_username" and password == "your_password": | |
# Assuming you want to return or process the Gradio URL | |
gradio_url = "https://srinukethanaboina-srunu.hf.space/gradio" | |
return {"message": "Authenticated successfully", "gradio_url": gradio_url} | |
else: | |
raise HTTPException(status_code=401, detail="Unauthorized") | |
# Run the app with uvicorn | |
if __name__ == "__main__": | |
uvicorn.run(app, host="0.0.0.0", port=7860) | |