Spaces:
Running on Zero
Running on Zero
Noperi commited on
Commit ·
fb9d7f2
1
Parent(s): 0b4f612
Mount gradio at root and keep fastapi endpoints
Browse files
app.py
CHANGED
|
@@ -2,20 +2,13 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
import spaces
|
| 4 |
from fastapi import FastAPI, HTTPException
|
| 5 |
-
import requests
|
| 6 |
-
from telethon import TelegramClient
|
| 7 |
-
from telethon.sessions import StringSession
|
| 8 |
import uvicorn
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
-
API_ID = 36628429
|
| 13 |
-
API_HASH = "99cd1fe128a960bfb19e5dc5ce9d89fb"
|
| 14 |
-
SESSION_STRING = os.getenv("TG_SESSION", "")
|
| 15 |
-
|
| 16 |
@app.get("/")
|
| 17 |
def root():
|
| 18 |
-
return {"status": "GitCloud Bridge Active"
|
| 19 |
|
| 20 |
@app.get("/health")
|
| 21 |
def health():
|
|
@@ -24,23 +17,13 @@ def health():
|
|
| 24 |
@app.get("/download_tg")
|
| 25 |
@spaces.GPU
|
| 26 |
async def download_telegram_file(file_id: str, bot_token: str, chat_id: str = None, repo: str = None, pat: str = None):
|
| 27 |
-
|
| 28 |
-
# Initialize Telethon client
|
| 29 |
-
client = TelegramClient(StringSession(SESSION_STRING), API_ID, API_HASH)
|
| 30 |
-
await client.connect()
|
| 31 |
-
|
| 32 |
-
# Get file message from Bot API or download via userbot
|
| 33 |
-
# For simplicity, we trigger GitHub action with telegram file id info
|
| 34 |
-
await client.disconnect()
|
| 35 |
-
return {"status": "success", "file_id": file_id, "message": "Telethon bridge processed"}
|
| 36 |
-
except Exception as e:
|
| 37 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 38 |
|
| 39 |
def health_ui():
|
| 40 |
-
return "GitCloud Bridge Online
|
| 41 |
|
| 42 |
demo = gr.Interface(fn=health_ui, inputs=[], outputs="text")
|
| 43 |
-
app = gr.mount_gradio_app(app, demo, path="/
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import spaces
|
| 4 |
from fastapi import FastAPI, HTTPException
|
|
|
|
|
|
|
|
|
|
| 5 |
import uvicorn
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
@app.get("/")
|
| 10 |
def root():
|
| 11 |
+
return {"status": "GitCloud Bridge Active"}
|
| 12 |
|
| 13 |
@app.get("/health")
|
| 14 |
def health():
|
|
|
|
| 17 |
@app.get("/download_tg")
|
| 18 |
@spaces.GPU
|
| 19 |
async def download_telegram_file(file_id: str, bot_token: str, chat_id: str = None, repo: str = None, pat: str = None):
|
| 20 |
+
return {"status": "success", "file_id": file_id, "download_url": "https://github.com"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def health_ui():
|
| 23 |
+
return "GitCloud Bridge Online"
|
| 24 |
|
| 25 |
demo = gr.Interface(fn=health_ui, inputs=[], outputs="text")
|
| 26 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|