Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -61,7 +61,6 @@ def translate_to_japanese(api_key, text):
|
|
61 |
st.title("English to Japanese Translator with Pronunciation")
|
62 |
st.markdown("Translate English text into Japanese and get its pronunciation (Romaji) using OpenAI's API.")
|
63 |
|
64 |
-
|
65 |
translateimg = Image.open("Untitled.png") # Ensure the file is in the correct directory
|
66 |
st.image(translateimg, use_container_width=True) # Adjust the size as per preference
|
67 |
|
@@ -77,8 +76,26 @@ if st.button("Translate"):
|
|
77 |
japanese_text, pronunciation = translate_to_japanese(api_key, english_text)
|
78 |
if pronunciation:
|
79 |
st.markdown("### Translation Result:")
|
|
|
80 |
st.write(f"**Japanese Output:** {japanese_text}")
|
81 |
st.write(f"**Pronunciation:** {pronunciation}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
translateimg2 = Image.open("v3.png") # Ensure the file is in the correct directory
|
83 |
st.image(translateimg2, width=150) # Adjust the size as per preference
|
84 |
else:
|
|
|
61 |
st.title("English to Japanese Translator with Pronunciation")
|
62 |
st.markdown("Translate English text into Japanese and get its pronunciation (Romaji) using OpenAI's API.")
|
63 |
|
|
|
64 |
translateimg = Image.open("Untitled.png") # Ensure the file is in the correct directory
|
65 |
st.image(translateimg, use_container_width=True) # Adjust the size as per preference
|
66 |
|
|
|
76 |
japanese_text, pronunciation = translate_to_japanese(api_key, english_text)
|
77 |
if pronunciation:
|
78 |
st.markdown("### Translation Result:")
|
79 |
+
st.write(f"**English Text:** {english_text}")
|
80 |
st.write(f"**Japanese Output:** {japanese_text}")
|
81 |
st.write(f"**Pronunciation:** {pronunciation}")
|
82 |
+
|
83 |
+
# Save the result in a text file
|
84 |
+
result_text = f"English Text: {english_text}\n\nJapanese Translation: {japanese_text}\nPronunciation: {pronunciation}"
|
85 |
+
|
86 |
+
# Write to a text file
|
87 |
+
with open("translation_result.txt", "w") as file:
|
88 |
+
file.write(result_text)
|
89 |
+
|
90 |
+
# Create a download button for the user to download the file
|
91 |
+
with open("translation_result.txt", "rb") as file:
|
92 |
+
st.download_button(
|
93 |
+
label="Download Translation Result",
|
94 |
+
data=file,
|
95 |
+
file_name="translation_result.txt",
|
96 |
+
mime="text/plain"
|
97 |
+
)
|
98 |
+
|
99 |
translateimg2 = Image.open("v3.png") # Ensure the file is in the correct directory
|
100 |
st.image(translateimg2, width=150) # Adjust the size as per preference
|
101 |
else:
|