Lukas Zaiser commited on
Commit
8035e67
·
1 Parent(s): 2b5bf31

update app

Browse files
Files changed (2) hide show
  1. app.py +34 -2
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,4 +1,36 @@
1
  import streamlit as st
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import MarianMTModel, MarianTokenizer
3
 
4
+ # Path to your model files
5
+ model_path = "lz039/translation-ft-de-bg"
6
+ tokenizer = MarianTokenizer.from_pretrained(model_path)
7
+ model = MarianMTModel.from_pretrained(model_path)
8
+
9
+ # Check if loaded successfully
10
+ print("Model and tokenizer loaded!")
11
+
12
+ # Streamlit app
13
+ st.title("Translation App")
14
+ st.write("Translate text from German to Bulgarian using your custom model!")
15
+
16
+ # Input text box
17
+ src_text = st.text_area("Enter text to translate:", placeholder="Type text in German here...")
18
+
19
+ # Button to trigger translation
20
+ if st.button("Translate"):
21
+ if src_text.strip(): # Ensure there's input text
22
+ try:
23
+ # Tokenize and generate translation
24
+ inputs = tokenizer(src_text, return_tensors="pt", padding=True)
25
+ translated = model.generate(**inputs)
26
+
27
+ # Decode the translation
28
+ result = tokenizer.decode(translated[0], skip_special_tokens=True)
29
+
30
+ # Display the translation
31
+ st.success("Translation:")
32
+ st.write(result)
33
+ except Exception as e:
34
+ st.error(f"An error occurred: {e}")
35
+ else:
36
+ st.warning("Please enter some text to translate!")
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ transformers