nouman66 commited on
Commit
8d7a00d
·
1 Parent(s): 83fef69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import streamlit as st
 
2
  from transformers import pipeline
3
 
4
- st.title("Multilingual Translator Chatbot")
5
 
6
  # Choose the translation models from Hugging Face
7
  translation_models = {
@@ -26,19 +27,29 @@ translator = pipeline(task="translation", model=translation_models[selected_tran
26
  # User input for translation
27
  user_input = st.text_area("Enter text for translation:", "")
28
 
 
29
  if st.button("Translate"):
30
- if user_input:
31
- # Perform translation
32
- translated_text = translator(user_input, max_length=500)[0]['translation_text']
33
- st.success(f"Translated Text: {translated_text}")
34
- else:
35
- st.warning("Please enter text for translation.")
 
 
 
 
 
 
 
 
 
36
 
37
  st.markdown("---")
38
 
39
  st.subheader("About")
40
  st.write(
41
- "This is a simple Multilingual Translator chatbot that uses the Hugging Face Transformers library."
42
  )
43
  st.write(
44
  "Select a translation model from the dropdown, enter text, and click 'Translate' to see the translation."
 
1
  import streamlit as st
2
+ import time
3
  from transformers import pipeline
4
 
5
+ st.title("Enhanced Multilingual Translator Chatbot")
6
 
7
  # Choose the translation models from Hugging Face
8
  translation_models = {
 
27
  # User input for translation
28
  user_input = st.text_area("Enter text for translation:", "")
29
 
30
+ # Display loading indicator
31
  if st.button("Translate"):
32
+ with st.spinner("Translating..."):
33
+ # Simulate translation delay for demonstration
34
+ time.sleep(2)
35
+ if user_input:
36
+ # Perform translation
37
+ translated_text = translator(user_input, max_length=500)[0]['translation_text']
38
+ st.success(f"Translated Text: {translated_text}")
39
+ else:
40
+ st.warning("Please enter text for translation.")
41
+
42
+ # Clear button to reset input and result
43
+ if st.button("Clear"):
44
+ user_input = ""
45
+ st.success("Input cleared.")
46
+ st.empty() # Clear previous results if any
47
 
48
  st.markdown("---")
49
 
50
  st.subheader("About")
51
  st.write(
52
+ "This is an enhanced Multilingual Translator chatbot that uses the Hugging Face Transformers library."
53
  )
54
  st.write(
55
  "Select a translation model from the dropdown, enter text, and click 'Translate' to see the translation."