Spaces:
Runtime error
Runtime error
Srinivasulu kethanaboina commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from fastapi import FastAPI, Request, HTTPException
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
import uvicorn
|
| 5 |
|
|
@@ -17,20 +17,16 @@ chat = gr.ChatInterface(fn=respond_to_chat, title="Chat with AI")
|
|
| 17 |
# Mount static files
|
| 18 |
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# Define the webhook endpoint
|
| 24 |
-
@app.post("/webhook")
|
| 25 |
-
async def webhook(request: Request):
|
| 26 |
-
data = await request.json()
|
| 27 |
-
username = data.get("username")
|
| 28 |
-
password = data.get("password")
|
| 29 |
-
|
| 30 |
if username == "your_username" and password == "your_password":
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
else:
|
| 35 |
raise HTTPException(status_code=401, detail="Unauthorized")
|
| 36 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from fastapi import FastAPI, Request, Depends, HTTPException
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
import uvicorn
|
| 5 |
|
|
|
|
| 17 |
# Mount static files
|
| 18 |
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
|
| 19 |
|
| 20 |
+
# Function to authenticate users
|
| 21 |
+
def authenticate(username: str, password: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
if username == "your_username" and password == "your_password":
|
| 23 |
+
return True
|
| 24 |
+
return False
|
| 25 |
+
|
| 26 |
+
@app.get("/gradio")
|
| 27 |
+
async def gradio_access(username: str, password: str):
|
| 28 |
+
if authenticate(username, password):
|
| 29 |
+
return gr.Interface.load("https://srinukethanaboina-srunu.hf.space/gradio") # Adjust URL if needed
|
| 30 |
else:
|
| 31 |
raise HTTPException(status_code=401, detail="Unauthorized")
|
| 32 |
|