nvd commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import asyncio
|
| 4 |
+
import logging
|
| 5 |
+
from bot import start_bot
|
| 6 |
+
|
| 7 |
+
logging.basicConfig(level=logging.INFO)
|
| 8 |
+
logger = logging.getLogger(__name__)
|
| 9 |
+
|
| 10 |
+
# A placeholder to show status (for debugging)
|
| 11 |
+
status = gr.Textbox(value="🟡 Starting...", label="Bot Status", interactive=False)
|
| 12 |
+
|
| 13 |
+
def update_status(message):
|
| 14 |
+
return message
|
| 15 |
+
|
| 16 |
+
async def main():
|
| 17 |
+
# Start the bot in the background
|
| 18 |
+
asyncio.create_task(start_bot(status_callback=lambda msg: logger.info(msg)))
|
| 19 |
+
# We can't easily update the Gradio interface from a separate thread,
|
| 20 |
+
# but the bot will run regardless. The startup log will appear in Space's logs.
|
| 21 |
+
|
| 22 |
+
# Build the Gradio interface
|
| 23 |
+
with gr.Blocks() as demo:
|
| 24 |
+
gr.Markdown("# 🤖 GitHub Release Bot for Bale")
|
| 25 |
+
status.render()
|
| 26 |
+
|
| 27 |
+
demo.queue()
|
| 28 |
+
# Launch the web interface, but do not block the event loop
|
| 29 |
+
demo.launch(prevent_thread_lock=True)
|
| 30 |
+
|
| 31 |
+
# Now start the bot
|
| 32 |
+
try:
|
| 33 |
+
asyncio.get_event_loop().run_until_complete(main())
|
| 34 |
+
except RuntimeError:
|
| 35 |
+
# If already running (e.g., in some environments)
|
| 36 |
+
asyncio.create_task(main())
|