Dooratre commited on
Commit
ec9e5dc
·
verified ·
1 Parent(s): 639b234

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -177
app.py CHANGED
@@ -1,27 +1,3 @@
1
- import requests
2
- from flask import Flask, render_template, request, send_from_directory
3
- from datetime import datetime
4
- from bs4 import BeautifulSoup
5
-
6
- app = Flask(__name__)
7
- with open('i.txt', 'r') as file:
8
- data = file.read()
9
-
10
- API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1"
11
- headers = {"Authorization": f"Bearer hf{data}"}
12
-
13
-
14
- def query(payload):
15
- response = requests.post(API_URL, headers=headers, json=payload)
16
- return response.json()
17
-
18
- API_URLAR = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-tc-big-en-ar"
19
-
20
- def queryar(ar):
21
- response = requests.post(API_URLAR, headers=headers, json=ar)
22
- return response.json()
23
-
24
-
25
  import telebot
26
  import requests
27
 
@@ -91,156 +67,4 @@ def echo_all(message):
91
  bot.reply_to(message, response_text)
92
  print(conversation_history)
93
 
94
- bot.polling()
95
-
96
- def generate_response(user_input):
97
- bitcoin_price, current_time = get_bitcoin_price()
98
- result = get_div_content(url)
99
- new_query = {
100
- "inputs": f"information about yourself: you are helpful assistant and your name is (Niron) , you are trained and proggramed by Mr.omar nuwara he is create you for btc trad and predicition start chat with user with use good Emojeis\n\nBtc Price Now :${bitcoin_price} date and time now: {current_time}\n\n Bitcoin history Tidy is (Date/open/high/low/close/adj close/Volume): {result}\n\nLast news:{news}\n\ntask:complete the reesponse:\n\nconversation history:{conversation_history}\n\nUser message:{user_input}\n\nmake sure to response about it and don't generate alot of words just based on the user message and Use Emojies\n\nresponse:",
101
- "parameters": {
102
- "top_k": 100,
103
- "top_p": 0.9,
104
- "temperature": 0.5,
105
- "repetition_penalty": 1.2,
106
- "max_new_tokens": 512,
107
- "max_time": 0,
108
- "return_full_text": True,
109
- "num_return_sequences": 1,
110
- "do_sample": False
111
- },
112
- "options": {
113
- "use_cache": False,
114
- "wait_for_model": False
115
- }
116
- }
117
-
118
- output = query(new_query)
119
-
120
- generated_text = output[0]['generated_text']
121
-
122
- response_start = generated_text.find('response:') + len('response:')
123
- response_end = generated_text.find('(end response)')
124
-
125
- response_text = generated_text[response_start:response_end].strip()
126
-
127
- note_index = response_text.find("Note:")
128
- if note_index != -1:
129
- response_text = response_text[:note_index].strip()
130
-
131
- instruction_index = response_text.find("### Instruction:")
132
- if instruction_index != -1:
133
- response_text = response_text[:instruction_index].strip()
134
-
135
- response_text = response_text.strip().replace('\n', '<br>')
136
-
137
- return response_text
138
- def get_bitcoin_price():
139
- current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
140
- url = 'https://api.coindesk.com/v1/bpi/currentprice.json'
141
- response = requests.get(url)
142
-
143
- if response.status_code == 200:
144
- data = response.json()
145
- bitcoin_price = data['bpi']['USD']['rate']
146
- return bitcoin_price, current_time
147
-
148
-
149
-
150
- @app.route('/assets/<path:path>')
151
- def send_static(path):
152
- return send_from_directory('assets', path)
153
-
154
-
155
- @app.route('/')
156
- def index():
157
- result = get_div_content(url)
158
- news = get_news(url)
159
- return render_template('admin.html')
160
-
161
- @app.route('/chat', methods=['POST'])
162
- def chat():
163
- user_input = request.get_json()['user_input']
164
-
165
- # Generate AI response based on user input
166
- response_text = generate_response(user_input)
167
- conversation_history.append({"User": user_input, "NIRON": response_text})
168
-
169
- # Update bitcoin price and current time
170
- bitcoin_price, current_time = get_bitcoin_price()
171
-
172
- return response_text
173
-
174
- @app.route('/trans')
175
- def trans():
176
- news = get_news(url)
177
- result = get_div_content(url)
178
-
179
- return render_template('arabic.html')
180
-
181
-
182
- @app.route('/arabic', methods=['POST'])
183
- def arabic():
184
- user_input = request.get_json()['user_input']
185
-
186
- # Generate AI response based on user input
187
- response_text = generate_response(user_input)
188
- conversation_history.append({"User": user_input, "\nAI": response_text})
189
- # Translate the response to Arabic using the Hugging Face API
190
- translation_payload = {
191
- "inputs": response_text,
192
- }
193
- output = queryar(translation_payload)
194
-
195
- translated_response = output[0]['translation_text']
196
-
197
- # Append the conversation history
198
-
199
-
200
- # Update bitcoin price and current time
201
- bitcoin_price, current_time = get_bitcoin_price()
202
-
203
- return translated_response
204
-
205
- def get_div_content(url):
206
- response = requests.get(url)
207
- soup = BeautifulSoup(response.content, 'html.parser')
208
-
209
- div_content = soup.find('div', {'id': '45'})
210
- if div_content:
211
- return div_content
212
- else:
213
- return None
214
-
215
- url = "https://dooratre-info.hf.space/?logs=container&__sign=eyJhbGciOiJFZERTQSJ9.eyJyZWFkIjp0cnVlLCJwZXJtaXNzaW9ucyI6eyJyZXBvLmNvbnRlbnQucmVhZCI6dHJ1ZX0sIm9uQmVoYWxmT2YiOnsia2luZCI6InVzZXIiLCJfaWQiOiI2NWIyYzMyNjJiZTk2NjBmMGIxMjg0MDAiLCJ1c2VyIjoiRG9vcmF0cmUifSwiaWF0IjoxNzEyNjgwNTY4LCJzdWIiOiIvc3BhY2VzL0Rvb3JhdHJlL2luZm8iLCJleHAiOjE3MTI3NjY5NjgsImlzcyI6Imh0dHBzOi8vaHVnZ2luZ2ZhY2UuY28ifQ.R_PX6Hw5SMheYTQWPGe1Qla9q8gVBU0mAFF_u8Iad06jSpZ9sPzZqquSowWn7PGVLRYBW21DnvqSwXIoNZ4CAA"
216
-
217
- result = get_div_content(url)
218
- print(result)
219
-
220
-
221
-
222
- @app.route('/clear_history')
223
- def clear_history():
224
- global conversation_history
225
- conversation_history = []
226
- return 'Conversation history cleared successfully'
227
-
228
-
229
-
230
- def get_news(url):
231
- response = requests.get(url)
232
- soup = BeautifulSoup(response.content, "html.parser")
233
-
234
- news = []
235
- for text in soup.stripped_strings:
236
- news.append(text)
237
-
238
- return news
239
-
240
- url = "https://www.newsbtc.com/"
241
- news = get_news(url)
242
- print(news)
243
-
244
-
245
- if __name__ == '__main__':
246
- app.run(host="0.0.0.0", port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import telebot
2
  import requests
3
 
 
67
  bot.reply_to(message, response_text)
68
  print(conversation_history)
69
 
70
+ bot.polling()