Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,20 +10,13 @@ from langchain.memory import ConversationBufferMemory
|
|
| 10 |
from langchain.chains import ConversationalRetrievalChain
|
| 11 |
from htmlTemplates import css, bot_template, user_template
|
| 12 |
from langchain.llms import HuggingFaceHub
|
| 13 |
-
import
|
|
|
|
| 14 |
|
| 15 |
# set this key as an environment variable
|
| 16 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets['huggingface_token']
|
| 17 |
###########################################################################################
|
| 18 |
-
|
| 19 |
-
txt_en=translators.translate_text(text,to_language='en',from_language='auto')
|
| 20 |
-
return txt_en
|
| 21 |
-
#########################################################################################
|
| 22 |
-
def trs_en_to_fa(text):
|
| 23 |
-
txt_fa=translators.translate_text(text,to_language='fa',from_language='en')
|
| 24 |
-
return txt_fa
|
| 25 |
-
##############################################################################################
|
| 26 |
-
|
| 27 |
def get_pdf_text(pdf_docs : list) -> str:
|
| 28 |
text = ""
|
| 29 |
for pdf in pdf_docs:
|
|
@@ -78,9 +71,11 @@ def handle_userinput(user_question:str):
|
|
| 78 |
else:
|
| 79 |
st.write("پاسخ ربات: " + message.content)
|
| 80 |
text1=message.content
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
#############################################################################################################
|
| 85 |
|
| 86 |
def main():
|
|
|
|
| 10 |
from langchain.chains import ConversationalRetrievalChain
|
| 11 |
from htmlTemplates import css, bot_template, user_template
|
| 12 |
from langchain.llms import HuggingFaceHub
|
| 13 |
+
from deep_translator import MyMemoryTranslator
|
| 14 |
+
|
| 15 |
|
| 16 |
# set this key as an environment variable
|
| 17 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets['huggingface_token']
|
| 18 |
###########################################################################################
|
| 19 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def get_pdf_text(pdf_docs : list) -> str:
|
| 21 |
text = ""
|
| 22 |
for pdf in pdf_docs:
|
|
|
|
| 71 |
else:
|
| 72 |
st.write("پاسخ ربات: " + message.content)
|
| 73 |
text1=message.content
|
| 74 |
+
# متنی که میخواهید ترجمه کنید
|
| 75 |
+
text_to_translate = text1
|
| 76 |
+
# متن را به فارسی ترجمه کنید
|
| 77 |
+
translated_text = MyMemoryTranslator(source='english', target='persian').translate(text_to_translate)
|
| 78 |
+
|
| 79 |
#############################################################################################################
|
| 80 |
|
| 81 |
def main():
|