dreyyyy commited on
Commit
934c758
·
verified ·
1 Parent(s): 61fccb4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -1,23 +1,26 @@
1
- import gradio as gr
2
  from transformers import pipeline
3
 
4
  # Load your Hugging Face model
5
  translator = pipeline("translation_en_to_fr", model="dreyyyy/EN-FR", device=-1) # Use CPU explicitly
6
 
 
 
 
 
7
 
8
- # Define the translation function
9
- def translate_text(input_text):
10
- result = translator(input_text)
11
- return result[0]["translation_text"]
12
 
13
- # Create the Gradio interface
14
- iface = gr.Interface(
15
- fn=translate_text,
16
- inputs="text",
17
- outputs="text",
18
- title="Translation Service",
19
- description="Translate text from English to French."
20
- )
21
-
22
- # Launch the app
23
- iface.launch()
 
 
1
+ import streamlit as st
2
  from transformers import pipeline
3
 
4
  # Load your Hugging Face model
5
  translator = pipeline("translation_en_to_fr", model="dreyyyy/EN-FR", device=-1) # Use CPU explicitly
6
 
7
+ # Streamlit app interface
8
+ st.title("Translation Service")
9
+ st.subheader("Translate English to French")
10
+ st.write("This app uses a Hugging Face model to translate English text into French.")
11
 
12
+ # Input text box
13
+ input_text = st.text_area("Enter English Text:", placeholder="Type your text here...")
 
 
14
 
15
+ # Translate button
16
+ if st.button("Translate"):
17
+ if input_text.strip():
18
+ # Perform translation
19
+ result = translator(input_text)
20
+ translated_text = result[0]["translation_text"]
21
+
22
+ # Display the translation
23
+ st.subheader("Translation in French:")
24
+ st.write(translated_text)
25
+ else:
26
+ st.warning("Please enter some text to translate.")