Dooratre commited on
Commit
e96e484
·
verified ·
1 Parent(s): 9823c9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -69
app.py CHANGED
@@ -1,70 +1,42 @@
1
- import telebot
2
  import requests
3
-
4
- with open('cokk.txt', 'r', encoding='utf-8') as file:
5
- info = file.read()
6
-
7
-
8
- # Replace 'YOUR_TOKEN' with your actual bot token
9
- bot = telebot.TeleBot('6990801595:AAE79xNVO1D_0SeWZlzYLE57Suwfp9GyKT8')
10
-
11
- def get_assistant_response(user_input):
12
- payload = {
13
- "mode": "chat",
14
- "chat_history": conversation_history,
15
- "data": {
16
- "query": f"{info}\n \n \n \n CHAT START HERE : \n \n Stuident : {user_input} \n C Learner :",
17
- "loader": "PDFReader",
18
- "text": ""
19
- }
20
- }
21
-
22
- response = requests.post(url2, headers=headers, json=payload)
23
- data = response.json()
24
-
25
- # Extract the response from the data
26
- response_text = data["data"]["response"]
27
-
28
- return response_text
29
-
30
-
31
-
32
- url2 = "https://api.braininc.net/be/vectordb/indexers/"
33
- headers = {
34
- "Authorization": "token 72ec00483379076f580eb8126f29da802a5140c3",
35
- "Content-Type": "application/json"
36
- }
37
-
38
- conversation_history = []
39
-
40
- @bot.message_handler(commands=['start', 'help'])
41
- def send_welcome(message):
42
- global conversation_history
43
- conversation_history=[]
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)