Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
|
|
|
|
3 |
|
4 |
-
# Initialize the
|
5 |
-
|
6 |
-
translator = deepl.Translator(DEEPL_API_KEY)
|
7 |
|
8 |
# Streamlit UI setup
|
9 |
st.set_page_config(page_title="AI-Powered Language Learning Assistant", page_icon="🧠", layout="wide")
|
@@ -14,40 +15,53 @@ st.markdown("""
|
|
14 |
Welcome to your AI-powered language assistant! Here you can:
|
15 |
- Translate words or sentences to different languages
|
16 |
- Learn and practice new vocabulary
|
17 |
-
- Get
|
18 |
""")
|
19 |
|
20 |
# Input field for text
|
21 |
text_input = st.text_input("Enter the text you want to translate or practice", "")
|
22 |
|
23 |
# Select target language for translation
|
24 |
-
language = st.selectbox("Select the language to translate to", ["
|
25 |
|
26 |
if text_input:
|
27 |
-
# Translate text using
|
28 |
st.subheader(f"Original Text: {text_input}")
|
29 |
-
translated_text = translator.
|
30 |
|
31 |
# Display translation
|
32 |
st.markdown(f"### Translated Text to {language.upper()}:")
|
33 |
-
st.write(translated_text
|
34 |
|
35 |
# Show pronunciation tip
|
36 |
st.subheader("Pronunciation Tip:")
|
37 |
-
st.write("Use
|
38 |
|
39 |
-
# Grammar Check (
|
40 |
st.subheader("Grammar Feedback:")
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
# Vocabulary practice section
|
44 |
st.markdown("---")
|
45 |
st.header("Vocabulary Practice")
|
46 |
word_input = st.text_input("Enter a word to get its definition and synonyms", "")
|
47 |
if word_input:
|
48 |
-
#
|
49 |
-
from transformers import pipeline
|
50 |
-
|
51 |
try:
|
52 |
word_model = pipeline("fill-mask", model="bert-base-uncased") # Using BERT to predict related words
|
53 |
result = word_model(f"The synonym of {word_input} is [MASK].")
|
@@ -58,5 +72,5 @@ if word_input:
|
|
58 |
# Footer for engagement
|
59 |
st.markdown("""
|
60 |
---
|
61 |
-
**Need more practice?** Visit [
|
62 |
""")
|
|
|
1 |
import streamlit as st
|
2 |
+
from googletrans import Translator # Free Google Translate API
|
3 |
+
from transformers import pipeline
|
4 |
+
import requests
|
5 |
|
6 |
+
# Initialize the Google Translator
|
7 |
+
translator = Translator()
|
|
|
8 |
|
9 |
# Streamlit UI setup
|
10 |
st.set_page_config(page_title="AI-Powered Language Learning Assistant", page_icon="🧠", layout="wide")
|
|
|
15 |
Welcome to your AI-powered language assistant! Here you can:
|
16 |
- Translate words or sentences to different languages
|
17 |
- Learn and practice new vocabulary
|
18 |
+
- Get grammar feedback.
|
19 |
""")
|
20 |
|
21 |
# Input field for text
|
22 |
text_input = st.text_input("Enter the text you want to translate or practice", "")
|
23 |
|
24 |
# Select target language for translation
|
25 |
+
language = st.selectbox("Select the language to translate to", ["es", "fr", "de", "it", "pt", "ru"])
|
26 |
|
27 |
if text_input:
|
28 |
+
# Translate text using googletrans
|
29 |
st.subheader(f"Original Text: {text_input}")
|
30 |
+
translated_text = translator.translate(text_input, dest=language).text
|
31 |
|
32 |
# Display translation
|
33 |
st.markdown(f"### Translated Text to {language.upper()}:")
|
34 |
+
st.write(translated_text)
|
35 |
|
36 |
# Show pronunciation tip
|
37 |
st.subheader("Pronunciation Tip:")
|
38 |
+
st.write("Use Google Translate or Forvo to practice pronunciation.")
|
39 |
|
40 |
+
# Grammar Check (using LanguageTool)
|
41 |
st.subheader("Grammar Feedback:")
|
42 |
+
grammar_check_url = "https://api.languagetool.org/v2/check"
|
43 |
+
params = {
|
44 |
+
"text": text_input,
|
45 |
+
"language": "en-US"
|
46 |
+
}
|
47 |
+
response = requests.post(grammar_check_url, data=params)
|
48 |
+
if response.status_code == 200:
|
49 |
+
result = response.json()
|
50 |
+
if result['matches']:
|
51 |
+
st.write("### Grammar Issues Found:")
|
52 |
+
for match in result['matches']:
|
53 |
+
st.write(f"- **{match['message']}** at position {match['offset']}-{match['offset']+match['length']}")
|
54 |
+
else:
|
55 |
+
st.write("No grammar issues found!")
|
56 |
+
else:
|
57 |
+
st.write("Grammar check failed. Try again later.")
|
58 |
|
59 |
+
# Vocabulary practice section using Hugging Face's BERT
|
60 |
st.markdown("---")
|
61 |
st.header("Vocabulary Practice")
|
62 |
word_input = st.text_input("Enter a word to get its definition and synonyms", "")
|
63 |
if word_input:
|
64 |
+
# Using Hugging Face's BERT model for related words (synonyms)
|
|
|
|
|
65 |
try:
|
66 |
word_model = pipeline("fill-mask", model="bert-base-uncased") # Using BERT to predict related words
|
67 |
result = word_model(f"The synonym of {word_input} is [MASK].")
|
|
|
72 |
# Footer for engagement
|
73 |
st.markdown("""
|
74 |
---
|
75 |
+
**Need more practice?** Visit [Google Translate](https://translate.google.com) for real-time translations and pronunciation!
|
76 |
""")
|