Spaces:
Build error
Build error
latterworks
commited on
Commit
•
5d04ea6
1
Parent(s):
c8bc787
Update app.py
Browse files
app.py
CHANGED
@@ -1,62 +1,46 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import openai
|
4 |
from dotenv import load_dotenv
|
|
|
5 |
|
6 |
# Load environment variables
|
7 |
load_dotenv()
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
try:
|
21 |
-
|
22 |
-
|
23 |
-
messages=[
|
24 |
-
{"role": "user", "content": user_content}
|
25 |
-
],
|
26 |
-
max_tokens=max_tokens
|
27 |
-
)
|
28 |
-
response = chat_completion.choices[0].message['content']
|
29 |
-
return response
|
30 |
except Exception as e:
|
31 |
-
return f"
|
32 |
|
33 |
-
# Gradio interface
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
#
|
38 |
-
with gr.Blocks() as demo:
|
39 |
-
gr.Markdown("# OpenAI Chat Completion & Greeting Interface")
|
40 |
-
|
41 |
-
# Greeting section
|
42 |
with gr.Row():
|
43 |
-
gr.
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
# OpenAI Chat Completion Section
|
50 |
with gr.Row():
|
51 |
-
gr.
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
chat_button = gr.Button("Get OpenAI Response")
|
57 |
-
chat_button.click(openai_chat_interface,
|
58 |
-
inputs=[user_input, model_input, max_tokens_input],
|
59 |
-
outputs=openai_response)
|
60 |
|
61 |
-
# Launch
|
62 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
|
|
3 |
from dotenv import load_dotenv
|
4 |
+
from telegram import Bot
|
5 |
|
6 |
# Load environment variables
|
7 |
load_dotenv()
|
8 |
+
TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
|
9 |
+
bot = Bot(token=TELEGRAM_BOT_TOKEN)
|
10 |
|
11 |
+
def send_message_to_user(chat_id, message):
|
12 |
+
"""Send a test message to a user via the bot."""
|
13 |
+
try:
|
14 |
+
bot.send_message(chat_id=chat_id, text=message)
|
15 |
+
return f"Message sent to chat ID {chat_id}"
|
16 |
+
except Exception as e:
|
17 |
+
return f"Failed to send message: {str(e)}"
|
18 |
|
19 |
+
def check_bot_status():
|
20 |
+
"""Check if the bot is online."""
|
21 |
try:
|
22 |
+
response = bot.get_me()
|
23 |
+
return f"Bot is online: {response.username}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
except Exception as e:
|
25 |
+
return f"Bot is offline: {str(e)}"
|
26 |
|
27 |
+
# Define the Gradio interface
|
28 |
+
with gr.Blocks() as dashboard:
|
29 |
+
gr.Markdown("# Telegram Bot Admin Dashboard")
|
30 |
|
31 |
+
# Bot status check
|
|
|
|
|
|
|
|
|
32 |
with gr.Row():
|
33 |
+
bot_status_button = gr.Button("Check Bot Status")
|
34 |
+
bot_status_output = gr.Textbox(label="Bot Status")
|
35 |
+
bot_status_button.click(check_bot_status, inputs=None, outputs=bot_status_output)
|
36 |
+
|
37 |
+
# Send a message
|
|
|
|
|
38 |
with gr.Row():
|
39 |
+
chat_id_input = gr.Textbox(label="Chat ID")
|
40 |
+
message_input = gr.Textbox(label="Message to Send")
|
41 |
+
send_message_button = gr.Button("Send Message")
|
42 |
+
send_message_output = gr.Textbox(label="Send Message Output")
|
43 |
+
send_message_button.click(send_message_to_user, inputs=[chat_id_input, message_input], outputs=send_message_output)
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
# Launch the dashboard
|
46 |
+
dashboard.launch()
|