ErikDaska commited on
Commit
10ff159
verified
1 Parent(s): cc6bfb8

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +48 -1
src/streamlit_app.py CHANGED
@@ -16,6 +16,50 @@ def instantiate_encoder(model_name: str, top_k : int, text : str) -> dict:
16
  pipe = pipeline("fill-mask", model=f"Iscte-Sintra/{model_name}", tokenizer=f"Iscte-Sintra/{model_name}", token=token)
17
  return pipe(text, top_k=top_k)
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  def build_decoder_page(model_name):
21
  try:
@@ -72,12 +116,15 @@ def build_encoder_page(model_name:str):
72
 
73
  # Your dictionary of models
74
  model_dict = {'RoBERTa-Kriolu': "Encoder",'Albertina-Kriolu':"Encoder" ,
75
- 'GPT2-Kriolu': "Decoder", "GPT2-Small": "Decoder","GPT2_v1.15": "Decoder", "GPT2_v1.17":"Decoder","GPT2_v1.18":"Decoder" }
76
 
77
  # Always appears at the top of the sidebar
78
  selected_model = st.sidebar.selectbox("Architecture", list(model_dict.keys()))
79
 
80
  if model_dict[selected_model] == "Encoder":
81
  build_encoder_page(selected_model)
 
 
 
82
  else:
83
  build_decoder_page(selected_model)
 
16
  pipe = pipeline("fill-mask", model=f"Iscte-Sintra/{model_name}", tokenizer=f"Iscte-Sintra/{model_name}", token=token)
17
  return pipe(text, top_k=top_k)
18
 
19
+ def instantiate_encoder_decoder(model_name: str, top_k : int, text : str) -> dict:
20
+ pipe = pipeline("translation", model=f"Iscte-Sintra/{model_name}", tokenizer=f"Iscte-Sintra/{model_name}", token=token)
21
+ return pipe(text, top_k=top_k)
22
+
23
+
24
+ def build_translation_page(model_name):
25
+ try:
26
+ st.title(f"{model_name} : Translation Task")
27
+
28
+ # Sidebar options
29
+ src_lang = st.sidebar.selectbox(
30
+ "Source Language",
31
+ ["auto", "en", "fr", "de", "es", "pt", "it", "nl", "zh", "ar"],
32
+ index=0,
33
+ )
34
+
35
+ tgt_lang = st.sidebar.selectbox(
36
+ "Target Language",
37
+ ["en", "fr", "de", "es", "pt", "it", "nl", "zh", "ar"],
38
+ index=4, # default to Portuguese in this example
39
+ )
40
+
41
+ text = st.text_area("Enter text to translate", "Katxor sta tr谩s di p贸rta.", height=100)
42
+
43
+ if st.button("Translate"):
44
+ if not text.strip():
45
+ st.warning("Please enter some text to translate!", icon="鈿狅笍")
46
+ return
47
+
48
+ # Call translation model (you can define your own implementation)
49
+ results = instantiate_translation_model(model_name, text, src_lang, tgt_lang)
50
+
51
+ if results:
52
+ st.subheader("Translation Result")
53
+ if isinstance(results, list):
54
+ for i, result in enumerate(results, start=1):
55
+ st.write(f"**Translation {i}:** {result}")
56
+ else:
57
+ st.write(f"**Translated Text:** {results}")
58
+ except Exception as e:
59
+ st.warning("An error occurred during translation!", icon="鈿狅笍")
60
+ st.warning(e)
61
+
62
+
63
 
64
  def build_decoder_page(model_name):
65
  try:
 
116
 
117
  # Your dictionary of models
118
  model_dict = {'RoBERTa-Kriolu': "Encoder",'Albertina-Kriolu':"Encoder" ,
119
+ 'GPT2-Kriolu': "Decoder", "GPT2_v1.15": "Decoder", "GPT2_v1.17":"Decoder","GPT2_v1.18":"Decoder", "GPT2-small":"Encoder-Decoder"}
120
 
121
  # Always appears at the top of the sidebar
122
  selected_model = st.sidebar.selectbox("Architecture", list(model_dict.keys()))
123
 
124
  if model_dict[selected_model] == "Encoder":
125
  build_encoder_page(selected_model)
126
+
127
+ elif model_dict[selected_model] == "Encoder-Decoder":
128
+ build_translation_page(selected_model)
129
  else:
130
  build_decoder_page(selected_model)