Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from fastapi import FastAPI, Request, Response
|
| 3 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
-
from pydantic import BaseModel
|
| 5 |
-
import threading
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
app = FastAPI()
|
| 9 |
-
|
| 10 |
-
# Allow CORS for your Bubble frontend
|
| 11 |
-
app.add_middleware(
|
| 12 |
-
CORSMiddleware,
|
| 13 |
-
allow_origins=['https://app.ingaze.ai'], # Replace with your actual Bubble app domain
|
| 14 |
-
allow_methods=['POST'],
|
| 15 |
-
allow_headers=['*'],
|
| 16 |
-
allow_credentials=True,
|
| 17 |
-
)
|
| 18 |
-
|
| 19 |
-
# State to track if token is received
|
| 20 |
token_received = {"status": False}
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
accessToken: str
|
| 25 |
-
|
| 26 |
-
@app.post('/api/set_token')
|
| 27 |
-
async def set_token(payload: TokenIn, response: Response):
|
| 28 |
token_received["status"] = True
|
| 29 |
-
|
| 30 |
-
response.set_cookie(
|
| 31 |
-
key='session_token',
|
| 32 |
-
value=session_token,
|
| 33 |
-
httponly=True,
|
| 34 |
-
secure=True,
|
| 35 |
-
samesite='none',
|
| 36 |
-
#domain='GuglielmoTor--LinkedinMonitor.hf.space', # Replace with your actual domain if needed
|
| 37 |
-
max_age=3600,
|
| 38 |
-
path='/'
|
| 39 |
-
)
|
| 40 |
-
return {'status': 'ok'}
|
| 41 |
|
| 42 |
-
#
|
| 43 |
def check_status():
|
| 44 |
return "✅ Code received" if token_received["status"] else "❌ Code not received"
|
| 45 |
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
import gradio as gr
|
| 54 |
-
from fastapi.middleware.wsgi import WSGIMiddleware
|
| 55 |
-
from gradio.routes import App as GradioApp
|
| 56 |
-
|
| 57 |
-
gradio_app = gr.mount_gradio_app(app, demo, path="/")
|
| 58 |
|
| 59 |
-
|
| 60 |
-
if __name__ == "__main__":
|
| 61 |
-
import uvicorn
|
| 62 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# shared state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
token_received = {"status": False}
|
| 5 |
|
| 6 |
+
# 1) this will be called by POST
|
| 7 |
+
def receive_token(accessToken: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
token_received["status"] = True
|
| 9 |
+
return {"status": "ok"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# 2) this just drives your UI
|
| 12 |
def check_status():
|
| 13 |
return "✅ Code received" if token_received["status"] else "❌ Code not received"
|
| 14 |
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
+
# we don’t actually show these widgets in the UI:
|
| 17 |
+
hidden_token = gr.Textbox(visible=False)
|
| 18 |
+
hidden_btn = gr.Button(visible=False)
|
| 19 |
+
# wire up the hidden POST→function
|
| 20 |
+
hidden_btn.click(fn=receive_token, inputs=hidden_token, outputs=[])
|
| 21 |
|
| 22 |
+
# your visible UI
|
| 23 |
+
status_box = gr.Textbox(value=check_status(), label="Token Status", interactive=False)
|
| 24 |
+
refresh = gr.Button("Refresh").click(fn=check_status, outputs=status_box)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|