tudorgeorgescu commited on
Commit
92aca6d
·
verified ·
1 Parent(s): d8f0dcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -29
app.py CHANGED
@@ -1,36 +1,21 @@
1
  import streamlit as st
2
- from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline, AutoModelForSeq2SeqLM
3
 
4
- # Load the keyphrase extraction models
5
- tokenizer1 = AutoTokenizer.from_pretrained("ml6team/keyphrase-extraction-kbir-inspec")
6
- model1 = AutoModelForTokenClassification.from_pretrained("ml6team/keyphrase-extraction-kbir-inspec")
7
- extractor1 = pipeline("ner", model=model1, tokenizer=tokenizer1)
8
-
9
- tokenizer2 = AutoTokenizer.from_pretrained("aglazkova/bart_finetuned_keyphrase_extraction")
10
- model2 = AutoModelForSeq2SeqLM.from_pretrained("aglazkova/bart_finetuned_keyphrase_extraction")
11
- extractor2 = pipeline("text2text-generation", model=model2, tokenizer=tokenizer2)
12
 
13
  # Streamlit app
14
- st.title("Keyphrase Extraction App")
15
- st.write("Enter text below to extract keyphrases using two different models:")
16
-
17
- # Text input
18
- user_input = st.text_area("Text Input", "")
19
 
20
- # Extract keyphrases
21
- if st.button("Extract Keyphrases"):
22
- if user_input:
23
- # Extract keyphrases using the first model
24
- keyphrases_model1 = extractor1(user_input)
25
- st.write("Extracted Keyphrases from `ml6team/keyphrase-extraction-kbir-inspec`:")
26
- for keyphrase in keyphrases_model1:
27
- st.write(keyphrase['word'])
28
 
29
- # Extract keyphrases using the second model
30
- tokenized_text = tokenizer2.prepare_seq2seq_batch([user_input], return_tensors='pt')
31
- translation = model2.generate(**tokenized_text)
32
- translated_text = tokenizer2.batch_decode(translation, skip_special_tokens=True)[0]
33
- st.write("Extracted Keyphrases from `aglazkova/bart_finetuned_keyphrase_extraction`:")
34
- st.write(translated_text)
 
35
  else:
36
- st.write("Please enter some text to extract keyphrases.")
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
 
4
+ # Initialize the translation pipeline
5
+ translator = pipeline("translation_ro_to_en")
 
 
 
 
 
 
6
 
7
  # Streamlit app
8
+ st.title("Romanian to English Translator")
 
 
 
 
9
 
10
+ # Input text
11
+ input_text = st.text_area("Enter text in Romanian:")
 
 
 
 
 
 
12
 
13
+ # Translate button
14
+ if st.button("Translate"):
15
+ if input_text:
16
+ # Perform translation
17
+ translation = translator(input_text)[0]['translation_text']
18
+ st.write("Translation:")
19
+ st.write(translation)
20
  else:
21
+ st.write("Please enter some text to translate.")