ali121300 commited on
Commit
8e8ccf4
1 Parent(s): 714ba2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -10,9 +10,14 @@ 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
 
14
  # set this key as an environment variable
15
  os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets['huggingface_token']
 
 
 
 
16
 
17
  def get_pdf_text(pdf_docs : list) -> str:
18
  text = ""
@@ -67,6 +72,7 @@ def handle_userinput(user_question:str):
67
  st.write("سوال کاربر: " + message.content)
68
  else:
69
  st.write("پاسخ ربات: " + message.content)
 
70
 
71
 
72
  def main():
@@ -88,7 +94,8 @@ def main():
88
 
89
 
90
  st.header("Chat with a Bot 🤖🦾 that tries to answer questions about multiple PDFs :books:")
91
- user_question = st.text_input("Ask a question about your documents:")
 
92
  if user_question:
93
  handle_userinput(user_question)
94
 
@@ -116,4 +123,4 @@ def main():
116
  st.write("compelete build model")
117
 
118
  if __name__ == "__main__":
119
- main()
 
10
  from langchain.chains import ConversationalRetrievalChain
11
  from htmlTemplates import css, bot_template, user_template
12
  from langchain.llms import HuggingFaceHub
13
+ import translators
14
 
15
  # set this key as an environment variable
16
  os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets['huggingface_token']
17
+ ###########################################################################################
18
+ def trs_fa_to_en(text):
19
+ txt_en=translators.translate_text(text,to_language='en',from_language='auto')
20
+ return txt_en
21
 
22
  def get_pdf_text(pdf_docs : list) -> str:
23
  text = ""
 
72
  st.write("سوال کاربر: " + message.content)
73
  else:
74
  st.write("پاسخ ربات: " + message.content)
75
+
76
 
77
 
78
  def main():
 
94
 
95
 
96
  st.header("Chat with a Bot 🤖🦾 that tries to answer questions about multiple PDFs :books:")
97
+ user_question_t = st.text_input("Ask a question about your documents:")
98
+ user_question=trs_fa_to_en(text= user_question_t)
99
  if user_question:
100
  handle_userinput(user_question)
101
 
 
123
  st.write("compelete build model")
124
 
125
  if __name__ == "__main__":
126
+ main()