File size: 2,824 Bytes
e089593 2e98d51 e089593 2e98d51 e089593 05c9152 76d7953 e089593 76d7953 05c9152 76d7953 2e98d51 05c9152 76d7953 2e98d51 76d7953 2e98d51 76d7953 2e98d51 05c9152 76d7953 2e98d51 05c9152 76d7953 2e98d51 22f6356 2e98d51 76d7953 2e98d51 05c9152 2e98d51 76d7953 2e98d51 76d7953 22f6356 76d7953 05c9152 2e98d51 05c9152 |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import streamlit as st
from googletrans import Translator # Free Google Translate API
from transformers import pipeline
import requests
# Initialize the Google Translator
translator = Translator()
# Streamlit UI setup
st.set_page_config(page_title="AI-Powered Language Learning Assistant", page_icon="🧠", layout="wide")
# Header and introduction
st.title("🧠 AI-Powered Language Learning Assistant")
st.markdown("""
Welcome to your AI-powered language assistant! Here you can:
- Translate words or sentences to different languages
- Learn and practice new vocabulary
- Get grammar feedback.
""")
# Input field for text
text_input = st.text_input("Enter the text you want to translate or practice", "")
# Select target language for translation
language = st.selectbox("Select the language to translate to", ["es", "fr", "de", "it", "pt", "ru"])
if text_input:
# Translate text using googletrans
st.subheader(f"Original Text: {text_input}")
translated_text = translator.translate(text_input, dest=language).text
# Display translation
st.markdown(f"### Translated Text to {language.upper()}:")
st.write(translated_text)
# Show pronunciation tip
st.subheader("Pronunciation Tip:")
st.write("Use Google Translate or Forvo to practice pronunciation.")
# Grammar Check (using LanguageTool)
st.subheader("Grammar Feedback:")
grammar_check_url = "https://api.languagetool.org/v2/check"
params = {
"text": text_input,
"language": "en-US"
}
response = requests.post(grammar_check_url, data=params)
if response.status_code == 200:
result = response.json()
if result['matches']:
st.write("### Grammar Issues Found:")
for match in result['matches']:
st.write(f"- **{match['message']}** at position {match['offset']}-{match['offset']+match['length']}")
else:
st.write("No grammar issues found!")
else:
st.write("Grammar check failed. Try again later.")
# Vocabulary practice section using Hugging Face's BERT
st.markdown("---")
st.header("Vocabulary Practice")
word_input = st.text_input("Enter a word to get its definition and synonyms", "")
if word_input:
# Using Hugging Face's BERT model for related words (synonyms)
try:
word_model = pipeline("fill-mask", model="bert-base-uncased") # Using BERT to predict related words
result = word_model(f"The synonym of {word_input} is [MASK].")
st.write(f"Synonyms or related words for **{word_input}**: {result}")
except Exception as e:
st.error("Error fetching vocabulary practice data.")
# Footer for engagement
st.markdown("""
---
**Need more practice?** Visit [Google Translate](https://translate.google.com) for real-time translations and pronunciation!
""")
|