david-oplatka commited on
Commit
c93e7fa
·
verified ·
1 Parent(s): 83335e9

Add Language Button

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -12,6 +12,8 @@ from langcodes import Language
12
  from PIL import Image
13
 
14
  max_examples = 4
 
 
15
 
16
  def isTrue(x) -> bool:
17
  if isinstance(x, bool):
@@ -57,11 +59,13 @@ def launch_bot():
57
  'source_data_desc': os.environ['source_data_desc'],
58
  'streaming': isTrue(os.environ.get('streaming', False)),
59
  'prompt_name': os.environ.get('prompt_name', None),
60
- 'examples': os.environ.get('examples', None)
 
61
  })
62
  st.session_state.cfg = cfg
63
  st.session_state.ex_prompt = None
64
- st.session_state.first_turn = True
 
65
  example_messages = [example.strip() for example in cfg.examples.split(",")]
66
  st.session_state.example_messages = [em for em in example_messages if len(em)>0][:max_examples]
67
 
@@ -76,8 +80,14 @@ def launch_bot():
76
  image = Image.open('Vectara-logo.png')
77
  st.image(image, width=175)
78
  st.markdown(f"## About\n\n"
79
- f"This demo uses Retrieval Augmented Generation to ask questions about {cfg.source_data_desc}\n\n")
80
 
 
 
 
 
 
 
81
  st.markdown("---")
82
  st.markdown(
83
  "## How this works?\n"
 
12
  from PIL import Image
13
 
14
  max_examples = 4
15
+ languages = {'English': 'en', 'Spanish': 'es', 'French': 'fr', 'German': 'de', 'Arabic': 'ar', 'Chinese': 'zh-cn',
16
+ 'Hebrew': 'he', 'Hindi': 'hi', 'Italian': 'it', 'Japanese': 'ja', 'Korean': 'ko', 'Portuguese': 'pt'}
17
 
18
  def isTrue(x) -> bool:
19
  if isinstance(x, bool):
 
59
  'source_data_desc': os.environ['source_data_desc'],
60
  'streaming': isTrue(os.environ.get('streaming', False)),
61
  'prompt_name': os.environ.get('prompt_name', None),
62
+ 'examples': os.environ.get('examples', None),
63
+ 'language': 'English'
64
  })
65
  st.session_state.cfg = cfg
66
  st.session_state.ex_prompt = None
67
+ st.session_state.first_turn = True
68
+ st.session_state.language = cfg.language
69
  example_messages = [example.strip() for example in cfg.examples.split(",")]
70
  st.session_state.example_messages = [em for em in example_messages if len(em)>0][:max_examples]
71
 
 
80
  image = Image.open('Vectara-logo.png')
81
  st.image(image, width=175)
82
  st.markdown(f"## About\n\n"
83
+ f"This demo uses Retrieval Augmented Generation to ask questions about {cfg.source_data_desc}\n")
84
 
85
+ cfg.language = st.selectbox('Language:', languages.keys())
86
+ if st.session_state.language != cfg.language:
87
+ st.session_state.language = cfg.language
88
+ st.rerun()
89
+
90
+ st.markdown("\n")
91
  st.markdown("---")
92
  st.markdown(
93
  "## How this works?\n"