File size: 2,126 Bytes
e089593 2e98d51 5b2548b e089593 5b2548b 76d7953 e089593 76d7953 05c9152 76d7953 5b2548b 76d7953 2e98d51 05c9152 5b2548b 2e98d51 5b2548b 2e98d51 5b2548b 2e98d51 5b2548b 05c9152 5b2548b 76d7953 5b2548b 22f6356 76d7953 05c9152 5b2548b 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 |
import streamlit as st
import requests
from transformers import pipeline
# Set up the page
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 (using LibreTranslate API)
- Learn and practice new vocabulary
- Get grammar feedback.
""")
# Translation Function (Using LibreTranslate API)
def translate_text(text, target_language):
url = "https://libretranslate.de/translate" # Free LibreTranslate API
payload = {
'q': text,
'source': 'en',
'target': target_language
}
response = requests.post(url, data=payload)
if response.status_code == 200:
return response.json()['translatedText']
else:
return "Translation failed."
# Vocabulary Practice Section using Hugging Face's BERT Model
st.markdown("---")
st.header("Vocabulary Practice")
word_input = st.text_input("Enter a word to get its definition and synonyms", "")
if word_input:
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(f"Error fetching vocabulary practice data: {e}")
# Translation Section
st.markdown("---")
st.header("Translation")
text_input = st.text_input("Enter the text you want to translate", "")
language = st.selectbox("Select the language to translate to", ["es", "fr", "de", "it", "pt", "ru"])
if text_input:
translated_text = translate_text(text_input, language)
st.subheader(f"Translated Text to {language.upper()}:")
st.write(translated_text)
# Footer for engagement
st.markdown("""
---
**Need more practice?** Visit [LibreTranslate API](https://libretranslate.de/) for real-time translations and Hugging Face for more language models!
""")
|