Update app.py
Browse files
app.py
CHANGED
|
@@ -1,85 +1,71 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
from
|
| 4 |
|
| 5 |
-
# Function to
|
| 6 |
-
def
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
return
|
| 18 |
-
else:
|
| 19 |
-
st.error("Failed to fetch recipes. Try again later.")
|
| 20 |
-
return []
|
| 21 |
|
| 22 |
# Streamlit UI setup
|
| 23 |
-
st.set_page_config(page_title="AI-Powered
|
| 24 |
-
|
| 25 |
-
# Add a background image (Optional)
|
| 26 |
-
def add_bg_image(image_path):
|
| 27 |
-
st.markdown(
|
| 28 |
-
f"""
|
| 29 |
-
<style>
|
| 30 |
-
.stApp {{
|
| 31 |
-
background-image: url({image_path});
|
| 32 |
-
background-size: cover;
|
| 33 |
-
background-position: center;
|
| 34 |
-
background-repeat: no-repeat;
|
| 35 |
-
}}
|
| 36 |
-
</style>
|
| 37 |
-
""", unsafe_allow_html=True
|
| 38 |
-
)
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# Header with title and icon
|
| 44 |
-
st.title("🍴 AI-Powered Recipe Generator with Pantry Integration")
|
| 45 |
st.markdown("""
|
| 46 |
-
Welcome to
|
|
|
|
|
|
|
|
|
|
| 47 |
""")
|
| 48 |
|
| 49 |
-
# Input field for
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
#
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
if recipes:
|
| 60 |
-
st.markdown("### 🍽️ Here are some recipe suggestions for you:")
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
# Loop through the recipes and display them in columns
|
| 66 |
-
for i, recipe in enumerate(recipes):
|
| 67 |
-
col = columns[i % 3] # Distribute recipes across columns
|
| 68 |
-
|
| 69 |
-
with col:
|
| 70 |
-
st.subheader(recipe['title'])
|
| 71 |
-
st.image(f"https://spoonacular.com/recipeImages/{recipe['id']}-312x231.jpg", width=200)
|
| 72 |
-
st.markdown(f"[View Full Recipe](https://spoonacular.com/recipes/{recipe['title'].replace(' ', '-')}-{recipe['id']})", unsafe_allow_html=True)
|
| 73 |
-
st.write("📝 **Ingredients**:")
|
| 74 |
-
st.write(", ".join([ingredient['name'] for ingredient in recipe['missedIngredients']]))
|
| 75 |
-
st.write("-" * 40)
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
st.markdown("""
|
| 82 |
---
|
| 83 |
-
**Need more
|
| 84 |
""")
|
| 85 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from googletrans import Translator
|
| 4 |
|
| 5 |
+
# Function to handle translation using Hugging Face or Google Translate
|
| 6 |
+
def translate_text(text, target_language="es"):
|
| 7 |
+
# Hugging Face pipeline for translation (can be used for various language pairs)
|
| 8 |
+
try:
|
| 9 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
|
| 10 |
+
result = translator(text, max_length=400)
|
| 11 |
+
return result[0]['translation_text']
|
| 12 |
+
except Exception as e:
|
| 13 |
+
st.error("Error translating text using Hugging Face. Trying Google Translate instead.")
|
| 14 |
+
# Fallback to Google Translate if Hugging Face fails
|
| 15 |
+
translator = Translator()
|
| 16 |
+
translated_text = translator.translate(text, dest=target_language).text
|
| 17 |
+
return translated_text
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Streamlit UI setup
|
| 20 |
+
st.set_page_config(page_title="AI-Powered Language Learning Assistant", page_icon="🧠", layout="wide")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# Header and introduction
|
| 23 |
+
st.title("🧠 AI-Powered Language Learning Assistant")
|
|
|
|
|
|
|
|
|
|
| 24 |
st.markdown("""
|
| 25 |
+
Welcome to your AI-powered language assistant! Here you can:
|
| 26 |
+
- Translate words or sentences to different languages
|
| 27 |
+
- Learn and practice new vocabulary
|
| 28 |
+
- Get pronunciation tips and grammar feedback.
|
| 29 |
""")
|
| 30 |
|
| 31 |
+
# Input field for text
|
| 32 |
+
text_input = st.text_input("Enter the text you want to translate or practice", "")
|
| 33 |
+
|
| 34 |
+
# Select target language for translation
|
| 35 |
+
language = st.selectbox("Select the language to translate to", ["es", "fr", "de", "it", "pt", "ru"])
|
| 36 |
+
|
| 37 |
+
if text_input:
|
| 38 |
+
# Translate text
|
| 39 |
+
st.subheader(f"Original Text: {text_input}")
|
| 40 |
+
translated_text = translate_text(text_input, target_language=language)
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
# Display translation
|
| 43 |
+
st.markdown(f"### Translated Text to {language.upper()}:")
|
| 44 |
+
st.write(translated_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
# Show pronunciation tip
|
| 47 |
+
st.subheader("Pronunciation Tip:")
|
| 48 |
+
st.write("Use an app like Google Translate or Forvo to practice pronunciation. If you want help with specific words, type them below.")
|
| 49 |
+
|
| 50 |
+
# Grammar Check (simple demo)
|
| 51 |
+
st.subheader("Grammar Feedback:")
|
| 52 |
+
st.write("For more advanced grammar feedback, please use language tools like Grammarly or LanguageTool.")
|
| 53 |
|
| 54 |
+
# Vocabulary practice section
|
| 55 |
+
st.markdown("---")
|
| 56 |
+
st.header("Vocabulary Practice")
|
| 57 |
+
word_input = st.text_input("Enter a word to get its definition and synonyms", "")
|
| 58 |
+
if word_input:
|
| 59 |
+
# Using Hugging Face API to fetch definitions and synonyms (this part can be expanded with a dedicated model)
|
| 60 |
+
try:
|
| 61 |
+
word_model = pipeline("fill-mask", model="bert-base-uncased") # Using BERT to predict related words
|
| 62 |
+
result = word_model(f"The synonym of {word_input} is [MASK].")
|
| 63 |
+
st.write(f"Synonyms or related words for **{word_input}**: {result}")
|
| 64 |
+
except Exception as e:
|
| 65 |
+
st.error("Error fetching vocabulary practice data.")
|
| 66 |
+
|
| 67 |
+
# Footer for engagement
|
| 68 |
st.markdown("""
|
| 69 |
---
|
| 70 |
+
**Need more practice?** Visit [Google Translate](https://translate.google.com) for real-time translations and pronunciation!
|
| 71 |
""")
|
|
|