Dooratre commited on
Commit
ddc8825
1 Parent(s): fcbe31c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -114
app.py CHANGED
@@ -1,117 +1,34 @@
1
-
2
- from flask import Flask, render_template, request, send_from_directory
3
  import requests
4
-
5
- with open('cokk.txt', 'r', encoding='utf-8') as file:
6
- info = file.read()
7
-
8
-
9
- app = Flask(__name__)
10
-
11
- def get_assistant_response(user_input):
12
- payload = {
13
- "mode": "chat",
14
- "chat_history": conversation_history,
15
- "data": {
16
- "query": f"{user_input}",
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
- response_text = response_text.strip().replace('\n', '<br>')
29
-
30
- # Check if the response contains ~
31
- if "~" in response_text:
32
- conversation_history.append({"\n ALex-9": response_text})
33
- # Extract the prompt between ~~
34
- prompt_start = response_text.index("~") + 1
35
- prompt_end = response_text.index("~", prompt_start)
36
- prompt = response_text[prompt_start:prompt_end]
37
-
38
- # Call the text-to-image API
39
- image_url = generate_image(prompt)
40
- response_text += f"<br><br><img src='{image_url}'>"
41
- # Delete the prompt from the response text
42
- response_text = response_text.replace("~" + prompt + "~", "")
43
- prompt = response_text
44
-
45
- return response_text
46
-
47
- def generate_image(prompt):
48
- url = "https://api.braininc.net/be/lambda/function/stableai"
49
- headers = {
50
- "Authorization": "token 72ec00483379076f580eb8126f29da802a5140c3",
51
- "Content-Type": "application/json",
52
- }
53
-
54
- payload = {
55
- "json": True,
56
- "prompt": f"{prompt} Realastic Photo 4K",
57
- "public_topic": "/studios/516104/wsuid_new-edge-4_nodeid_editor-4/imageGen/1719250632789"
58
- }
59
-
60
- response = requests.post(url, headers=headers, json=payload)
61
- data = response.json()
62
-
63
- cdn_url = data["cdn_url"]
64
- return cdn_url
65
-
66
- url2 = "https://api.braininc.net/be/vectordb/indexers/"
67
- headers = {
68
- "Authorization": "token 72ec00483379076f580eb8126f29da802a5140c3",
69
- "Content-Type": "application/json;charset=UTF-8",
70
-
71
- }
72
-
73
- conversation_history = []
74
-
75
- @app.route('/')
76
- def home():
77
- global conversation_history
78
- conversation_history = []
79
- conversation_history.append({
80
- "role": "user",
81
- "content":f"SYSTEM PROMPT : Hello i hope you are okay , you are AI in my app okay ? so you most follow this : {info}\n \n just make sure to add best greet talk about you in 10 to 15 words okay ? and Start to ask users Quistions and some tips to make good and intresting conversation now let's start",
82
- "additional_kwargs": {}
83
- })
84
- conversation_history.append({
85
- "role": "assistant",
86
- "content": "Hello! I'm CLEANER, an AI model trained to teach students the basics of programming in the C language. I'm here to help you understand the course material and prepare for exams. Feel free to ask me any questions or seek guidance on any topic related to C programming. Let's make your learning experience enjoyable and successful! 😊📚 Now, let's begin our conversation. How can I assist you today? Do you have any specific questions or topics you'd like to discuss?",
87
- "additional_kwargs": {}
88
- })
89
-
90
- return render_template('ai-chat-bot.html')
91
-
92
- @app.route('/get_response', methods=['POST'])
93
- def get_response():
94
- user_input = request.form['user_input']
95
- conversation_history.append({
96
- "role": "user",
97
- "content":f"{user_input}",
98
- "additional_kwargs": {}
99
- })
100
-
101
- if user_input.lower() == "exit":
102
- return "exit"
103
-
104
- response_text = get_assistant_response(user_input)
105
- conversation_history.append({
106
- "role": "assistant",
107
- "content": f"{response_text}",
108
- "additional_kwargs": {}
109
- })
110
- return response_text
111
-
112
- @app.route('/desine/<path:path>')
113
- def send_static(path):
114
- return send_from_directory('desine', path)
115
 
116
  if __name__ == '__main__':
117
- app.run(host='0.0.0.0' , port=7860)
 
 
 
1
  import requests
2
+ import time
3
+
4
+ # Replace 'YOUR_BOT_TOKEN' with your actual bot token
5
+ bot_token = '7405960993:AAH1YTmoam4-Afk_QHsAcAObrdXwAlzfsaQ'
6
+
7
+ def send_message(chat_id, text):
8
+ url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
9
+ params = {'chat_id': chat_id, 'text': text}
10
+ response = requests.get(url, params=params)
11
+ print(response.json())
12
+
13
+ def handle_message(message):
14
+ chat_id = message['chat']['id']
15
+ text = message['text']
16
+ if text == '/start':
17
+ send_message(chat_id, 'Hi')
18
+
19
+ def main():
20
+ offset = None
21
+ while True:
22
+ url = f'https://api.telegram.org/bot{bot_token}/getUpdates'
23
+ params = {'offset': offset}
24
+ response = requests.get(url, params=params)
25
+ data = response.json()
26
+ if data['ok']:
27
+ for update in data['result']:
28
+ offset = update['update_id'] + 1
29
+ if 'message' in update:
30
+ handle_message(update['message'])
31
+ time.sleep(1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  if __name__ == '__main__':
34
+ main()