mathslearn commited on
Commit
e698753
·
verified ·
1 Parent(s): ff3d735

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py CHANGED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer
2
+
3
+ from langchain.chat_models import ChatOpenAI
4
+ from langchain.chains import ConversationChain
5
+ from langchain.chains.conversation.memory import ConversationBufferWindowMemory
6
+ from langchain.prompts import PromptTemplate
7
+
8
+ import gradio as gr
9
+
10
+ REPO_ID = "ksh-nyp/llama-2-7b-chat-TCMKB"
11
+
12
+ # Load the model and tokenizer from Hugging Face's model hub
13
+ model = AutoModelForCausalLM.from_pretrained(REPO_ID)
14
+ tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
15
+
16
+ llm = ChatOpenAI(model=model, tokenizer=tokenizer)
17
+
18
+ if 'buffer_memory' not in st.session_state:
19
+ st.session_state.buffer_memory = ConversationBufferWindowMemory(k=3)
20
+
21
+ conversation = ConversationChain(
22
+ llm=llm,
23
+ memory=st.session_state.buffer_memory,
24
+ verbose=True
25
+ )
26
+
27
+ context = """
28
+ Act as an OrderBot, you work collecting orders in a delivery only fast food restaurant called My Dear Frankfurt. \
29
+ First welcome the customer, in a very friendly way, then collect the order. \
30
+ You wait to collect the entire order, beverages included, \
31
+ then summarize it and check for a final time if everything is okay or the customer wants to add anything else. \
32
+ Finally, you collect the payment. \
33
+ Make sure to clarify all options, extras, and sizes to uniquely identify the item from the menu. \
34
+ You respond in a short, very friendly style. \
35
+ The menu includes:
36
+ burgers 12.95, 10.00, 7.00
37
+ frankfurts 10.95, 9.25, 6.50
38
+ sandwiches 11.95, 9.75, 6.75
39
+ fries 4.50, 3.50
40
+ salad 7.25
41
+ Toppings:
42
+ extra cheese 2.00,
43
+ mushrooms 1.50
44
+ martra sausage 3.00
45
+ canadian bacon 3.50
46
+ romesco sauce 1.50
47
+ peppers 1.00
48
+ Drinks:
49
+ coke 3.00, 2.00, 1.00
50
+ sprite 3.00, 2.00, 1.00
51
+ vichy catalan 5.00
52
+ """
53
+
54
+ prompt_template = PromptTemplate.from_template('''system role :{context} \
55
+ user:{query}\
56
+ assistance:
57
+ ''')
58
+
59
+ # Define Gradio Interface
60
+ iface = gr.Interface(
61
+ fn=lambda query: conversation.run(prompt_template.format(context=context, query=query)),
62
+ inputs=gr.Textbox(),
63
+ outputs=gr.Textbox(),
64
+ live=True,
65
+ capture_session=True
66
+ )
67
+
68
+ # Launch Gradio Interface
69
+ iface.launch()