Dooratre commited on
Commit
8a5db1d
1 Parent(s): 2ba8a59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -2,7 +2,7 @@ import requests
2
  from flask import Flask, render_template, request, send_from_directory
3
  from datetime import datetime
4
  from bs4 import BeautifulSoup
5
- from googletrans import Translator
6
  app = Flask(__name__)
7
  with open('i.txt', 'r') as file:
8
  data = file.read()
@@ -15,6 +15,13 @@ def query(payload):
15
  response = requests.post(API_URL, headers=headers, json=payload)
16
  return response.json()
17
 
 
 
 
 
 
 
 
18
  conversation_history = []
19
 
20
  def generate_response(user_input):
@@ -109,15 +116,21 @@ def arabic():
109
 
110
  # Generate AI response based on user input
111
  response_text = generate_response(user_input)
 
 
 
 
 
 
112
 
113
- # Translate the response to Arabic
114
- translator = Translator()
115
- translated_response = translator.translate(response_text, dest='ar').text
116
 
117
- conversation_history.append({"User": user_input, "AI": response_text})
 
118
 
119
  # Update bitcoin price and current time
120
  bitcoin_price, current_time = get_bitcoin_price()
 
121
  return translated_response
122
 
123
  def get_div_content(url):
@@ -158,6 +171,7 @@ def get_news(url):
158
  url = "https://www.newsbtc.com/"
159
  news = get_news(url)
160
  print(news)
 
161
 
162
  if __name__ == '__main__':
163
  app.run(host="0.0.0.0", port=7860)
 
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()
 
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
  conversation_history = []
26
 
27
  def generate_response(user_input):
 
116
 
117
  # Generate AI response based on user input
118
  response_text = generate_response(user_input)
119
+ conversation_history.append({"User": user_input, "\nAI": response_text})
120
+ # Translate the response to Arabic using the Hugging Face API
121
+ translation_payload = {
122
+ "inputs": response_text,
123
+ }
124
+ output = queryar(translation_payload)
125
 
126
+ translated_response = output[0]['translation_text']
 
 
127
 
128
+ # Append the conversation history
129
+
130
 
131
  # Update bitcoin price and current time
132
  bitcoin_price, current_time = get_bitcoin_price()
133
+
134
  return translated_response
135
 
136
  def get_div_content(url):
 
171
  url = "https://www.newsbtc.com/"
172
  news = get_news(url)
173
  print(news)
174
+
175
 
176
  if __name__ == '__main__':
177
  app.run(host="0.0.0.0", port=7860)