aditi2222 commited on
Commit
ceb20b6
Β·
1 Parent(s): 7996524

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -54
app.py CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  """
2
  πŸ—£οΈ Translator - Translate text from one language to another.
3
  Application file made with Streamlit.
@@ -15,23 +19,44 @@ from available_models import MODELS
15
 
16
  st.set_page_config(page_title="Translator", page_icon="πŸ—£οΈ")
17
  st.title("πŸ—£οΈ Translator")
18
-
 
 
 
 
 
 
19
  st.write("To add a new model, hit me up! ⬆️")
20
 
21
  with st.expander(label="❓ How does it work", expanded=True):
22
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- lang1, lang2 = st.columns(2)
25
- lang1.selectbox(
26
- "Source Language", ["πŸ‡«πŸ‡· French"],
27
  key="input_lang", index=1,
28
  )
29
- lang2.selectbox(
30
- "Target Language", ["πŸ‡¬πŸ‡§ English"],
31
  key="output_lang", index=0,
32
  )
33
 
34
- selected_model = MODELS[f"{st.session_state['input_lang']}->{st.session_state['output_lang']}"]
35
 
36
 
37
  if selected_model[0] == None:
@@ -66,49 +91,9 @@ else:
66
 
67
  st.success("πŸ—£οΈ Translated!")
68
  st.write(f"**Translation:** {' '.join(text_to_translate)}")
69
-
70
-
71
-
72
-
73
-
74
- '''
75
-
76
-
77
- import torch
78
- from transformers import BartTokenizer, BartForConditionalGeneration
79
- import gradio as gr
80
- from transformers import AutoTokenizer, AutoModelWithLMHead, TranslationPipeline
81
- from transformers import pipeline
82
-
83
- pipe= pipeline('text2text-generation', model="SEBIS/legal_t5_small_trans_fr_en")
84
- def generate_text(inp):
85
- output=pipe(inp, forced_bos_token_id=pipe.tokenizer.get_lang_id('en'))
86
- tln=output[0]
87
- for item in tln:
88
- result=tln[item]
89
- return result
90
- #Gradio Interface
91
-
92
- model = BartForConditionalGeneration.from_pretrained("facebook/bart-large-cnn")
93
- tokenizer = BartTokenizer.from_pretrained("facebook/bart-large-cnn")
94
-
95
- def article_summarization(result):
96
- input_ = str(result) + ' </s>'
97
- # generate summary
98
- input_ids = tokenizer.encode(result, return_tensors='pt')
99
- summary_ids = model.generate(input_ids,
100
- min_length=20,
101
- max_length=12000)
102
-
103
- summary_text = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
104
- return(summary_text)
105
-
106
-
107
- #iface = gr.Interface(fn=article_summarization,title="Summarization in English",description="facebook/bart-large-cnn for summarization in English", inputs=(lines=50,['text']), outputs=["text"])
108
-
109
- iface = gr.Interface(fn=article_summarization,title="Summarization in English",description="facebook/bart-large-cnn for summarization in English", inputs=gr.inputs.Textbox(lines=50, placeholder="Enter newspaper article to be summarized"), outputs=["result"])
110
-
111
- iface.launch()
112
-
113
-
114
- '''
 
1
+ "raw
2
+ history
3
+ blame
4
+ 5.44 kB
5
  """
6
  πŸ—£οΈ Translator - Translate text from one language to another.
7
  Application file made with Streamlit.
 
19
 
20
  st.set_page_config(page_title="Translator", page_icon="πŸ—£οΈ")
21
  st.title("πŸ—£οΈ Translator")
22
+ st.subheader("Translation made fast and easy.")
23
+ st.markdown("""
24
+ [![GitHub](https://img.shields.io/badge/-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/ChainYo)
25
+ [![HuggingFace](https://img.shields.io/badge/-yellow.svg?style=for-the-badge&logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDIwMDEwOTA0Ly9FTiIKICJodHRwOi8vd3d3LnczLm9yZy9UUi8yMDAxL1JFQy1TVkctMjAwMTA5MDQvRFREL3N2ZzEwLmR0ZCI+CjxzdmcgdmVyc2lvbj0iMS4wIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiB3aWR0aD0iMTc1LjAwMDAwMHB0IiBoZWlnaHQ9IjE3NS4wMDAwMDBwdCIgdmlld0JveD0iMCAwIDE3NS4wMDAwMDAgMTc1LjAwMDAwMCIKIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaWRZTWlkIG1lZXQiPgoKPGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMC4wMDAwMDAsMTc1LjAwMDAwMCkgc2NhbGUoMC4xMDAwMDAsLTAuMTAwMDAwKSIKZmlsbD0iIzAwMDAwMCIgc3Ryb2tlPSJub25lIj4KPHBhdGggZD0iTTU2MyAxMjM2IGMtMjkgLTEzIC02MyAtNTkgLTYzIC04NiAwIC0yNiAzMyAtODAgNTIgLTg2IDE1IC00IDI2IDEKNDMgMjEgMjAgMjYgMjQgMjcgNTMgMTcgMjggLTkgMzMgLTggNDIgOCAxNyAzMiAxMSA2OSAtMTcgOTkgLTM0IDM3IC02OCA0NQotMTEwIDI3eiIvPgo8cGF0aCBkPSJNMTA2NCAxMjQwIGMtNTAgLTIwIC03NyAtODYgLTU0IC0xMzAgOSAtMTYgMTQgLTE3IDQyIC04IDI5IDEwIDMzIDkKNTUgLTE3IDIxIC0yNCAyNyAtMjYgNDggLTE3IDMxIDE0IDUxIDc2IDM2IDExNCAtMTcgNDYgLTg0IDc2IC0xMjcgNTh6Ii8+CjxwYXRoIGQ9Ik02MDAgODg4IGMwIC00OSAxNiAtOTggNTAgLTE1MSA4NSAtMTM0IDMyNSAtMTM0IDQxMCAwIDUxIDgwIDY5IDE4MwozMSAxODMgLTEwIDAgLTUwIC0xNSAtODcgLTMyIC02MCAtMjkgLTc5IC0zMyAtMTQ5IC0zMyAtNzAgMCAtODkgNCAtMTQ5IDMzCi0zNyAxNyAtNzcgMzIgLTg3IDMyIC0xNSAwIC0xOSAtNyAtMTkgLTMyeiIvPgo8L2c+Cjwvc3ZnPgo=)](https://huggingface.co/ChainYo)
26
+ [![LinkedIn](https://img.shields.io/badge/-%230077B5.svg?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/thomas-chaigneau-dev/)
27
+ [![Discord](https://img.shields.io/badge/Chainyo%233610-%237289DA.svg?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/)
28
+ """)
29
  st.write("To add a new model, hit me up! ⬆️")
30
 
31
  with st.expander(label="❓ How does it work", expanded=True):
32
+ st.markdown("""
33
+ **Translator** is a **simple tool** that allows you to **translate text** from one language to another.
34
+ **Translator** is powered by the [Transformers library](https://huggingface.co/transformers) and uses the
35
+ [Helsinki-NLP](https://huggingface.co/Helsinki-NLP) models.
36
+ Choose the **source language**, the **target language** and add some **text to translate**.
37
+ **Translator** will translate the text and **save the output in a text file**. It cuts the sentences by following
38
+ the punctuation marks.
39
+ The output file content will also be displayed in the browser to help you understand the translation and choose
40
+ if you want to download it.
41
+ There is **no limit to the number of characters** that can be translated.
42
+ The only limit is the time you are ready to wait! πŸ€—
43
+ *P.S. I have built this tool to help me start writing blog posts in different languages. I am a French native speaker
44
+ and I will use it to translate my potential future blog posts in English.*
45
+ *P.P.S. I am a **Junior ML Engineer** passionate about **machine learning** and **data science**. Reach out to me by
46
+ clicking on the socials badges above.*
47
+ """)
48
 
49
+ lang1, lang2 = st.columns(2)
50
+ lang1.selectbox(
51
+ "Source Language", ["πŸ‡¬πŸ‡§ English", "πŸ‡«πŸ‡· French", "πŸ‡©πŸ‡ͺ German", "πŸ‡ͺπŸ‡Έ Spanish", "πŸ‡·πŸ‡Ί Russian"],
52
  key="input_lang", index=1,
53
  )
54
+ lang2.selectbox(
55
+ "Target Language", ["πŸ‡¬πŸ‡§ English", "πŸ‡«πŸ‡· French", "πŸ‡©πŸ‡ͺ German", "πŸ‡ͺπŸ‡Έ Spanish", "πŸ‡·πŸ‡Ί Russian"],
56
  key="output_lang", index=0,
57
  )
58
 
59
+ selected_model = MODELS[f"{st.session_state['input_lang']}->{st.session_state['output_lang']}"]
60
 
61
 
62
  if selected_model[0] == None:
 
91
 
92
  st.success("πŸ—£οΈ Translated!")
93
  st.write(f"**Translation:** {' '.join(text_to_translate)}")
94
+ st.download_button(
95
+ label="Download translated text",
96
+ data="\n".join(text_to_translate),
97
+ file_name=f"{st.session_state['input_lang']}-{st.session_state['output_lang']}-{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}.txt",
98
+ mime="text/plain"
99
+ )