Antoine245 commited on
Commit
8b369c5
·
1 Parent(s): 2a11265

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -41
app.py CHANGED
@@ -6,63 +6,62 @@ import google.generativeai as palm
6
  palm.configure(api_key=os.environ.get("palm_key"))
7
 
8
  defaults = {
9
- 'model': 'models/chat-bison-001',
10
- 'temperature': 0.3,
11
- 'candidate_count': 1,
12
- 'top_k': 40,
13
- 'top_p': 0.95,
14
  }
15
  context = "You are an order bot with only 3 types of pizzas: Margherita, Cheesy-Bacon and Vegetarian. Prices are small (9$), medium (11$) and large (13$). You can offer 2 types of drinks coke and mountain dew."
16
  examples = [
17
- [
18
- "Hi, I want to order pizzas.",
19
- "Hello, we have 3 types of pizzas: Margherita, Cheesy-Bacon and Vegetarian. Prices are small (9$), medium (11$) and large (13$)."
20
- ],
21
- [
22
- "I want a large margherita and a medium cheesy-bacon.",
23
- "Do you want any drinks? We have coke (3$) or Mountain dew (5$)."
24
- ],
25
- [
26
- "Yes 2 cokes.",
27
- "Total will be 19$. Please enter your address and phone number"
28
- ],
29
- [
30
- "Paris eiffel tower, 0653145863",
31
- "Perfect ! Do you need anything else?"
32
- ],
33
- [
34
- "No thanks.",
35
- "Have a nice day!\nHere is the sum up: \n{\npizza_type_1: \"margherita\",\npizza_type_2: \"cheesy-bacon\",\npizza_size_1: \"L\",\npizza_size_2: \"M\",\ndrink_1: \"coke\",\ndrink_2: \"coke\",\ntotal_price: \"19\",\naddress: \"Paris, Eiffel Tower\",\nphone_number: \"0653145863\"\n}\nDo you want to change anything?"
36
- ],
37
- [
38
- "Yes, i'd like to change margherita size to M.",
39
- "Have a nice day!\nHere is the sum up: \n{\npizza_type_1: \"margherita\",\npizza_type_2: \"cheesy-bacon\",\npizza_size_1: \"M\",\npizza_size_2: \"M\",\ndrink_1: \"coke\",\ndrink_2: \"coke\",\ntotal_price: \"19\",\naddress: \"Paris, Eiffel Tower\",\nphone_number: \"0653145863\"\n}\nDo you want to change anything?"
40
- ],
41
- [
42
- "No thanks",
43
- "Have a nice day!"
44
- ]
45
  ]
46
 
47
- history = ['']
48
 
49
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
50
  chatbot = gr.Chatbot()
51
  msg = gr.Textbox()
52
  btn = gr.Button("Submit", variant="primary")
53
- # gr.ClearButton([msg, chatbot])
54
  clear = gr.Button("Clear")
55
-
56
  def user(user_message, history):
57
- return gr.update(value=""), history + [[user_message, None]]
 
58
 
59
  def bot(history):
60
- try:
61
  bot_message = palm.chat(
62
  context=context,
63
  examples=examples,
64
- messages=history[-1][0]
65
- # messages=history
66
  )
67
 
68
  history[-1][1] = ""
@@ -89,4 +88,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
89
  clear.click(lambda: None, None, chatbot, queue=False)
90
 
91
  demo.queue()
92
- demo.launch(debug=True)
 
6
  palm.configure(api_key=os.environ.get("palm_key"))
7
 
8
  defaults = {
9
+ 'model': 'models/chat-bison-001',
10
+ 'temperature': 0.3,
11
+ 'candidate_count': 1,
12
+ 'top_k': 40,
13
+ 'top_p': 0.95,
14
  }
15
  context = "You are an order bot with only 3 types of pizzas: Margherita, Cheesy-Bacon and Vegetarian. Prices are small (9$), medium (11$) and large (13$). You can offer 2 types of drinks coke and mountain dew."
16
  examples = [
17
+ [
18
+ "Hi, I want to order pizzas.",
19
+ "Hello, we have 3 types of pizzas: Margherita, Cheesy-Bacon and Vegetarian. Prices are small (9$), medium (11$) and large (13$)."
20
+ ],
21
+ [
22
+ "I want a large margherita and a medium cheesy-bacon.",
23
+ "Do you want any drinks? We have coke (3$) or Mountain dew (5$)."
24
+ ],
25
+ [
26
+ "Yes 2 cokes.",
27
+ "Total will be 19$. Please enter your address and phone number"
28
+ ],
29
+ [
30
+ "Paris eiffel tower, 0653145863",
31
+ "Perfect ! Do you need anything else?"
32
+ ],
33
+ [
34
+ "No thanks.",
35
+ "Have a nice day!\nHere is the sum up: \n{\npizza_type_1: \"margherita\",\npizza_type_2: \"cheesy-bacon\",\npizza_size_1: \"L\",\npizza_size_2: \"M\",\ndrink_1: \"coke\",\ndrink_2: \"coke\",\ntotal_price: \"19\",\naddress: \"Paris, Eiffel Tower\",\nphone_number: \"0653145863\"\n}\nDo you want to change anything?"
36
+ ],
37
+ [
38
+ "Yes, i'd like to change margherita size to M.",
39
+ "Have a nice day!\nHere is the sum up: \n{\npizza_type_1: \"margherita\",\npizza_type_2: \"cheesy-bacon\",\npizza_size_1: \"M\",\npizza_size_2: \"M\",\ndrink_1: \"coke\",\ndrink_2: \"coke\",\ntotal_price: \"19\",\naddress: \"Paris, Eiffel Tower\",\nphone_number: \"0653145863\"\n}\nDo you want to change anything?"
40
+ ],
41
+ [
42
+ "No thanks",
43
+ "Have a nice day!"
44
+ ]
45
  ]
46
 
47
+ history = [['']]
48
 
49
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
50
  chatbot = gr.Chatbot()
51
  msg = gr.Textbox()
52
  btn = gr.Button("Submit", variant="primary")
 
53
  clear = gr.Button("Clear")
54
+
55
  def user(user_message, history):
56
+ history.append([user_message, None])
57
+ return gr.update(value=""), history
58
 
59
  def bot(history):
60
+ try:
61
  bot_message = palm.chat(
62
  context=context,
63
  examples=examples,
64
+ messages=[h[0] for h in history]
 
65
  )
66
 
67
  history[-1][1] = ""
 
88
  clear.click(lambda: None, None, chatbot, queue=False)
89
 
90
  demo.queue()
91
+ demo.launch()