CHEFSTORY / app.py
namann007's picture
Update app.py
9727e6c verified
raw
history blame contribute delete
No virus
2.42 kB
import streamlit as st
from langchain_google_genai import ChatGoogleGenerativeAI
# Set up API key
api_key = st.secrets["GOOGLE_API_KEY"]
st.title("The Chef Story Chatbot")
def get_bot_response(user_input):
# Initialize the model with the API key
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=api_key)
# Define prompts for specific questions
if "menu" in user_input.lower():
return format_menu()
elif "special" in user_input.lower():
return "Today's special is Grilled Salmon with Lemon Butter Sauce. Don't miss it!"
elif "offers" in user_input.lower():
return "We have a 20% discount on all orders above $50. Use code CHEF20 at checkout."
elif "delivery" in user_input.lower():
return "We offer home delivery for a minimal charge of $5. Free delivery for orders above $30."
# For other questions, use the chatbot model
prompt = f"User asked: {user_input}"
response = llm.invoke(prompt)
return response.content
def format_menu():
menu = {
"Italian": {
"Margherita Pizza": "$12",
"Pasta Carbonara": "$15"
},
"Chinese": {
"Sweet and Sour Chicken": "$13",
"Kung Pao Shrimp": "$14"
},
"Indian": {
"Chicken Curry": "$16",
"Paneer Tikka": "$14"
},
"Thai": {
"Pad Thai": "$14",
"Green Curry": "$15"
},
"Desserts": {
"Cheesecake": "$8",
"Chocolate Lava Cake": "$9"
},
"Kids Special": {
"Chicken Nuggets": "$7",
"Mini Pizzas": "$8"
},
"Low Calorie Foods": {
"Grilled Chicken Salad": "$12",
"Quinoa Bowl": "$11"
}
}
menu_text = "Here is our full menu with prices:\n\n"
for category, items in menu.items():
menu_text += f"**{category}**:\n"
for item, price in items.items():
menu_text += f"- {item}: {price}\n"
menu_text += "\n"
return menu_text
# Create a Streamlit form
with st.form("chat_form"):
user_input = st.text_input("You:")
submitted = st.form_submit_button("Send")
if submitted:
if user_input:
response = get_bot_response(user_input)
st.write(f"Bot: {response}")
else:
st.error("Please enter a message.")