cecilemacaire commited on
Commit
550ce4a
1 Parent(s): 765d42b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -146,25 +146,25 @@ with col2:
146
  st.text_area("Transcription :", transcription['text'])
147
  st.session_state['transcription'] = transcription['text']
148
 
149
-
150
- if st.session_state['transcription'] is not None:
151
- inputs = tokenizer(transcription['text'].lower(), return_tensors="pt").input_ids
152
- outputs = model.generate(inputs, max_new_tokens=40, do_sample=True, top_k=30, top_p=0.95)
153
- pred = tokenizer.decode(outputs[0], skip_special_tokens=True)
154
 
155
- sentence_to_map = process_output_trad(pred)
156
- pictogram_ids = [get_id_picto_from_predicted_lemma(lexicon, lemma) for lemma in sentence_to_map]
157
- st.session_state['pictogram_ids'] = [get_id_picto_from_predicted_lemma(lexicon, lemma) for lemma in sentence_to_map]
158
 
159
 
160
- if st.session_state['pictogram_ids'] is not None:
161
- html = generate_html(st.session_state['pictogram_ids'])
162
- st.components.v1.html(html, height=500, scrolling=True)
163
 
164
- # Container to hold the download button
165
- pdf_path = generate_pdf(st.session_state['pictogram_ids'])
166
- with open(pdf_path, "rb") as pdf_file:
167
- st.download_button(label="Télécharger la traduction en PDF", data=pdf_file, file_name="pictograms.pdf", mime="application/pdf")
168
 
169
  # record_audio = st_audiorec()
170
  # if record_audio:
 
146
  st.text_area("Transcription :", transcription['text'])
147
  st.session_state['transcription'] = transcription['text']
148
 
149
+ with st.spinner("Affichage des pictogrammes..."):
150
+ if st.session_state['transcription'] is not None:
151
+ inputs = tokenizer(transcription['text'].lower(), return_tensors="pt").input_ids
152
+ outputs = model.generate(inputs, max_new_tokens=40, do_sample=True, top_k=30, top_p=0.95)
153
+ pred = tokenizer.decode(outputs[0], skip_special_tokens=True)
154
 
155
+ sentence_to_map = process_output_trad(pred)
156
+ pictogram_ids = [get_id_picto_from_predicted_lemma(lexicon, lemma) for lemma in sentence_to_map]
157
+ st.session_state['pictogram_ids'] = [get_id_picto_from_predicted_lemma(lexicon, lemma) for lemma in sentence_to_map]
158
 
159
 
160
+ if st.session_state['pictogram_ids'] is not None:
161
+ html = generate_html(st.session_state['pictogram_ids'])
162
+ st.components.v1.html(html, height=500, scrolling=True)
163
 
164
+ # Container to hold the download button
165
+ pdf_path = generate_pdf(st.session_state['pictogram_ids'])
166
+ with open(pdf_path, "rb") as pdf_file:
167
+ st.download_button(label="Télécharger la traduction en PDF", data=pdf_file, file_name="pictograms.pdf", mime="application/pdf")
168
 
169
  # record_audio = st_audiorec()
170
  # if record_audio: