kamau1 commited on
Commit
0db34bd
·
verified ·
1 Parent(s): eda3bd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -27,7 +27,7 @@ os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets['huggingface_token']
27
  st.set_page_config(page_title="SemaNaPDF", page_icon="📚",)
28
 
29
  # Sema Translator
30
- Public_Url = 'https://lewiskimaru-helloworld.hf.space/' #endpoint
31
 
32
  def translate(userinput, target_lang, source_lang=None):
33
  if source_lang:
@@ -42,7 +42,7 @@ def translate(userinput, target_lang, source_lang=None):
42
  print(type(result))
43
  source_lange = source_lang
44
  translation = result['translated_text']
45
- return source_lange, translation
46
  else:
47
  url = f"{Public_Url}/translate_detect/"
48
  data = {
@@ -54,7 +54,7 @@ def translate(userinput, target_lang, source_lang=None):
54
  result = response.json()
55
  source_lange = result['source_language']
56
  translation = result['translated_text']
57
- return source_lange, translation
58
 
59
  def get_pdf_text(pdf : Union[str, bytes, bytearray]) -> str:
60
  reader = PdfReader(pdf)
@@ -102,11 +102,11 @@ def get_conversation_chain(vectorstore:FAISS) -> ConversationalRetrievalChain:
102
 
103
  st.markdown("""
104
  <style>
105
- div.stSpinner> {
106
  text-align:center;
107
  align-items: center;
108
  justify-content: center;
109
- }div
110
  </style>""", unsafe_allow_html=True)
111
 
112
 
@@ -144,7 +144,7 @@ def main():
144
 
145
  user_langd, Queryd = translate(user_question, 'eng_Latn')
146
  st.session_state.messages.append({"role": "user", "content": user_question})
147
- response = st.session_state.conversation({"question": user_question}) #Queryd
148
  st.session_state.chat_history = response["chat_history"]
149
 
150
  output = translate(response['answer'], user_langd, 'eng_Latn')[1] # translated response
 
27
  st.set_page_config(page_title="SemaNaPDF", page_icon="📚",)
28
 
29
  # Sema Translator
30
+ Public_Url = 'https://lewiskimaru-helloworld.hf.space' #endpoint
31
 
32
  def translate(userinput, target_lang, source_lang=None):
33
  if source_lang:
 
42
  print(type(result))
43
  source_lange = source_lang
44
  translation = result['translated_text']
45
+
46
  else:
47
  url = f"{Public_Url}/translate_detect/"
48
  data = {
 
54
  result = response.json()
55
  source_lange = result['source_language']
56
  translation = result['translated_text']
57
+ return source_lange, translation
58
 
59
  def get_pdf_text(pdf : Union[str, bytes, bytearray]) -> str:
60
  reader = PdfReader(pdf)
 
102
 
103
  st.markdown("""
104
  <style>
105
+ .stSpinner {
106
  text-align:center;
107
  align-items: center;
108
  justify-content: center;
109
+ }
110
  </style>""", unsafe_allow_html=True)
111
 
112
 
 
144
 
145
  user_langd, Queryd = translate(user_question, 'eng_Latn')
146
  st.session_state.messages.append({"role": "user", "content": user_question})
147
+ response = st.session_state.conversation({"question": Queryd}) #Queryd
148
  st.session_state.chat_history = response["chat_history"]
149
 
150
  output = translate(response['answer'], user_langd, 'eng_Latn')[1] # translated response