Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# prompt: create a streamlit app that will take as an input a russian text and will translate it into english
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
import torch
|
5 |
+
|
6 |
+
def translate(text):
|
7 |
+
# Tokenize the text
|
8 |
+
input_ids = tokenizer.batch_encode_plus([text], return_tensors="pt")["input_ids"]
|
9 |
+
|
10 |
+
# Generate the translation
|
11 |
+
outputs = model.generate(input_ids, max_length=100)
|
12 |
+
|
13 |
+
# Decode the translation
|
14 |
+
translation = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
15 |
+
|
16 |
+
return translation
|
17 |
+
|
18 |
+
def main():
|
19 |
+
# Get the user's input
|
20 |
+
text = st.text_input("Enter a Russian text to translate:")
|
21 |
+
|
22 |
+
# Translate the text
|
23 |
+
translation = translate(text)
|
24 |
+
|
25 |
+
# Display the translation
|
26 |
+
st.text(translation)
|
27 |
+
|
28 |
+
if __name__ == "__main__":
|
29 |
+
main()
|