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