Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,70 +1,42 @@
|
|
1 |
-
import telebot
|
2 |
import requests
|
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 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
bot.reply_to(message, "Hello there")
|
46 |
-
|
47 |
-
@bot.message_handler(func=lambda message: True)
|
48 |
-
def echo_all(message):
|
49 |
-
chat_id = message.chat.id
|
50 |
-
user_input = message.text
|
51 |
-
conversation_history.append({
|
52 |
-
"role": "user",
|
53 |
-
"content": f"Stuident :{user_input}",
|
54 |
-
"additional_kwargs": {}
|
55 |
-
})
|
56 |
-
|
57 |
-
if user_input.lower() == "exit":
|
58 |
-
bot.reply_to(message, "Goodbye!")
|
59 |
-
return
|
60 |
-
|
61 |
-
response_text = get_assistant_response(user_input)
|
62 |
-
conversation_history.append({
|
63 |
-
"role": "assistant",
|
64 |
-
"content": f"C Learner :{response_text}",
|
65 |
-
"additional_kwargs": {}
|
66 |
-
})
|
67 |
-
bot.reply_to(message, response_text)
|
68 |
-
print(conversation_history)
|
69 |
-
|
70 |
-
bot.polling()
|
|
|
|
|
1 |
import requests
|
2 |
+
from flask import Flask, render_template
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
# Replace 'YOUR_BOT_TOKEN' with your actual bot token
|
7 |
+
bot_token = '6990801595:AAE79xNVO1D_0SeWZlzYLE57Suwfp9GyKT8'
|
8 |
+
|
9 |
+
def send_message(chat_id, text):
|
10 |
+
url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
|
11 |
+
params = {'chat_id': chat_id, 'text': text}
|
12 |
+
response = requests.get(url, params=params)
|
13 |
+
return response.json()
|
14 |
+
|
15 |
+
def handle_message(message):
|
16 |
+
chat_id = message['chat']['id']
|
17 |
+
text = message['text']
|
18 |
+
|
19 |
+
if text == '/start':
|
20 |
+
send_message(chat_id, 'Hi')
|
21 |
+
|
22 |
+
@app.route('/')
|
23 |
+
def home():
|
24 |
+
return render_template('index.html')
|
25 |
+
|
26 |
+
def main():
|
27 |
+
offset = None
|
28 |
+
|
29 |
+
while True:
|
30 |
+
url = f'https://api.telegram.org/bot{bot_token}/getUpdates'
|
31 |
+
params = {'offset': offset}
|
32 |
+
response = requests.get(url, params=params)
|
33 |
+
data = response.json()
|
34 |
+
|
35 |
+
if data['ok']:
|
36 |
+
for update in data['result']:
|
37 |
+
offset = update['update_id'] + 1
|
38 |
+
if 'message' in update:
|
39 |
+
handle_message(update['message'])
|
40 |
+
|
41 |
+
if __name__ == '__main__':
|
42 |
+
main(host='0.0.0.0',port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|