namann007's picture
Update app.py
53f2718 verified
raw
history blame
No virus
4.9 kB
import streamlit as st
from langchain_google_genai import ChatGoogleGenerativeAI
from datetime import datetime
st.set_page_config(page_title="THE CHEF STORY", layout="wide")
# Page styling without using HTML
st.markdown(
"""
<style>
.main-title {
font-size: 2.5rem;
color: #333;
text-align: center;
font-weight: bold;
}
.subtitle {
font-size: 1.25rem;
color: #555;
text-align: center;
margin-bottom: 2rem;
}
.chat-history {
margin-bottom: 2rem;
}
.chat-box {
padding: 1rem;
border-radius: 10px;
margin-bottom: 1rem;
max-width: 80%;
}
.customer {
background-color: #DCF8C6;
color: #000;
align-self: flex-end;
}
.bot {
background-color: #E6E6E6;
color: #000;
align-self: flex-start;
}
.input-container {
display: flex;
align-items: center;
}
.input-field {
flex: 1;
margin-right: 10px;
}
.button {
display: inline-block;
padding: 10px 20px;
background-color: #007BFF;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: px;
margin: 20px;
text-align: center;
}
.button:hover {
background-color: #0056b3;
}
</style>
""",
unsafe_allow_html=True
)
# Title and subtitle
st.markdown('<div class="main-title">THE CHEF STORY</div>', unsafe_allow_html=True)
st.markdown('<div class="subtitle">Where your cravings find a home</div>', unsafe_allow_html=True)
def chef_bot(question, chat_history):
history = "\n".join([f"{sender}: {message}" for sender, message in chat_history])
prompt = (
f"You are the chatbot for The Chef Story, a multi-cuisine restaurant chain known for its delicious food and vibrant folklore shows. "
f"The Chef Story is located in various cities, providing online ordering and home delivery services with minimal charges. "
f"We offer a variety of cuisines, including Indian, Chinese, Italian, low-calorie options, kids' specials, and desserts, all priced in dollars. "
f"Here's the current interaction history:\n{history}\nCustomer: {question}\nYou: "
f"Always respond positively, providing detailed information about our menu, services, and special events. "
f"Include brief descriptions and prices of the menu items when asked, and make sure to mention our website (www.thechefstory.com) for more information. "
f"Welcome the customer warmly and offer a great experience at The Chef Story. "
f"If it's the birthday of any of the customer's companions, offer a free cake to the group. "
f"If the customer has rated the restaurant on the website, offer a coupon of 20% discount. "
f"If it is a weekend, offer a free drink to the customer. "
f"If the customer is visiting on weekends between 3 to 6 p.m., offer a free snack item."
f"Highlight the above 4 offers in bullet points and bold and small, cute emojis."
f'For the first message of customer you always have to begin with "Welcome to the Chef Story. Discover the perfect blend of taste and ambiance at The Chef Story. Our passion for food and commitment to quality shine through in every dish. Join us for a culinary journey where exceptional flavors and warm, inviting service come together to create a dining experience like no other."'
)
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
answer = llm.invoke(prompt).content
return answer
if 'chat_history' not in st.session_state:
st.session_state['chat_history'] = []
def handle_chat():
user_input = st.session_state['user_input']
if user_input:
bot_response = chef_bot(user_input, st.session_state.chat_history)
st.session_state.chat_history.append(("Customer", user_input))
st.session_state.chat_history.append(("Chef Story", bot_response))
st.session_state['user_input'] = ""
def generate_response():
handle_chat()
# Welcome message
st.markdown("Welcome to The Chef Story where culinary excellence meets folklore magic. We are thrilled to have you here. Hope you will enjoy your meal and have an amazing day.")
# Display chat history
if st.session_state.chat_history:
for sender, message in st.session_state.chat_history:
class_name = "customer" if sender == "Customer" else "bot"
st.markdown(f'<div class="chat-box {class_name}">{message}</div>', unsafe_allow_html=True)
# Input field for user message
st.text_input("How may I assist you today?", key="user_input", on_change=generate_response, placeholder="Ask me anything...")
# Button for generating response
# if st.button("Generate Response"):
# generate_response()