File size: 1,122 Bytes
fada25c
f84af85
4a1be1e
 
 
 
cd7fdea
4a1be1e
 
 
 
 
 
 
 
 
 
 
 
f84af85
 
4f7c970
f84af85
 
 
 
 
 
 
4f7c970
 
4a1be1e
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gradio as gr
from fastapi import FastAPI, Request, Depends, 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")

# Function to authenticate users
def authenticate(username: str, password: str):
    if username == "your_username" and password == "your_password":
        return True
    return False

@app.get("/gradio")
async def gradio_access(username: str, password: str):
    if authenticate(username, password):
        return gr.Interface.load("https://srinukethanaboina-srunu.hf.space/gradio")  # Adjust URL if needed
    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)