CoolFace
Apppublic

chwee/myWebChatPizza

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py101 linesDownload Raw Back to root
1import os2from dotenv import load_dotenv3from langchain_google_genai import ChatGoogleGenerativeAI4from langchain.prompts import PromptTemplate5from langchain.chains import LLMChain6 7# load_dotenv()8 9# GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")10 11GOOGLE_API_KEY = "AIzaSyBLawKS571DfI7ZzRpzDy6mC892qV2tab8"12 13llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_API_KEY)14from langchain.prompts.prompt import PromptTemplate15history=""16# Template using jinja2 syntax17template = """18<s>[INST] <<SYS>>19You are OrderBot, an automated service to collect orders for a pizza restaurant. \20You first greet the customer, then collects the order, \21and then asks if it's a pickup or delivery. \22You wait to collect the entire order, then summarize it and check for a final \23time if the customer wants to add anything else. \24If it's a delivery, you ask for an address. \25Finally you collect the payment.\26Make sure to clarify all options, extras and sizes to uniquely \27identify the item from the menu.\28You respond in a short, very conversational friendly style. \29The menu includes \30pepperoni pizza  12.95, 10.00, 7.00 \31cheese pizza   10.95, 9.25, 6.50 \32eggplant pizza   11.95, 9.75, 6.75 \33fries 4.50, 3.50 \34greek salad 7.25 \35Toppings: \36extra cheese 2.00, \37mushrooms 1.50 \38sausage 3.00 \39canadian bacon 3.50 \40AI sauce 1.50 \41peppers 1.00 \42Drinks: \43coke 3.00, 2.00, 1.00 \44sprite 3.00, 2.00, 1.00 \45bottled water 5.00 \46<</SYS>>47 48 49Current conversation:50{{ history }}51 52{% if history %}53    <s>[INST] Human: {{ input }} [/INST] OrderBot: </s>54{% else %}55    Human: {{ input }} [/INST] OrderBot: </s>56{% endif %}57"""58 59prompt = PromptTemplate(60    input_variables=["history", "input"],61    template=template,62    template_format="jinja2"63)64 65from langchain.chains import ConversationChain66from langchain.memory import ConversationBufferMemory67 68# Initialize the conversation chain69conversation = ConversationChain(70    llm=llm,71    memory=ConversationBufferMemory(),72    prompt=prompt,73    verbose=False74)75 76 77# Start the conversation78def predict(message: str, history: str):79    response = conversation.predict(input=message)80 81    return response82 83 84import gradio as gr85 86# Set up the user interface87interface = gr.ChatInterface(88    clear_btn=None,89    fn=predict,90    retry_btn=None,91    undo_btn=None,92)93 94# Launch the user interface95interface.launch(96    height=600,97    inline=True,98    share=True,99    width=800,100    share = True101)