engrphoenix commited on
Commit
76d7953
·
verified ·
1 Parent(s): 05c9152

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -71
app.py CHANGED
@@ -1,85 +1,71 @@
1
  import streamlit as st
2
- import requests
3
- from PIL import Image
4
 
5
- # Function to fetch recipes based on ingredients
6
- def get_recipes(ingredients):
7
- # Spoonacular API Key (Sign up on Spoonacular to get your API key)
8
- api_key = 'your_spoonacular_api_key' # Replace with your Spoonacular API key
9
-
10
- # API URL for recipe search
11
- url = f'https://api.spoonacular.com/recipes/findByIngredients?ingredients={",".join(ingredients)}&number=5&apiKey={api_key}'
12
-
13
- response = requests.get(url)
14
-
15
- if response.status_code == 200:
16
- recipes = response.json()
17
- return recipes
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 Recipe Generator", page_icon="🍽️", layout="wide")
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
- # Add background image (you can choose your own)
41
- add_bg_image("https://your-image-url.jpg")
42
-
43
- # Header with title and icon
44
- st.title("🍴 AI-Powered Recipe Generator with Pantry Integration")
45
  st.markdown("""
46
- Welcome to the AI-powered recipe generator! Simply enter the ingredients you have in your pantry, and we'll suggest some delicious recipes for you. 🥘
 
 
 
47
  """)
48
 
49
- # Input field for ingredients (comma-separated)
50
- ingredients_input = st.text_input("Enter ingredients you have (e.g., eggs, cheese, tomatoes)", "")
51
- if ingredients_input:
52
- ingredients = [ingredient.strip().lower() for ingredient in ingredients_input.split(',')]
53
-
54
- st.write(f"Looking for recipes with: **{', '.join(ingredients)}**")
55
-
56
- # Fetch recipes based on the entered ingredients
57
- recipes = get_recipes(ingredients)
58
-
59
- if recipes:
60
- st.markdown("### 🍽️ Here are some recipe suggestions for you:")
61
 
62
- # Display the recipes in a grid layout
63
- columns = st.columns(3) # Create a 3-column layout
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
- else:
78
- st.warning("No recipes found. Try using different ingredients!")
 
 
 
 
 
79
 
80
- # Add a footer for engagement
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  st.markdown("""
82
  ---
83
- **Need more ideas?** Visit our [Spoonacular API Documentation](https://spoonacular.com/food-api) for more recipe inspiration!
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
  """)