File size: 758 Bytes
e288957
4fd7379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8fca559
4fd7379
 
 
 
 
8fca559
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
import gradio as gr
from fastapi import FastAPI, Request
from google_auth import get_auth_url, fetch_token
from agent import run_agent
import json

app = FastAPI()

@app.get("/login")
def login():
    auth_url, state = get_auth_url()
    return {"auth_url": auth_url}

@app.get("/auth/callback")
async def callback(request: Request):
    code = request.query_params.get("code")
    token_data = fetch_token(code)

    with open("user_token.json", "w") as f:
        json.dump(token_data, f)

    return {"status": "Login successful. You may close this tab."}

def chat_interface(message):
    return run_agent(message)

demo = gr.Interface(
    fn=chat_interface,
    inputs="text",
    outputs="text"
)

demo.launch(server_name="0.0.0.0", server_port=7860)