Antoine245 commited on
Commit
e648b17
·
1 Parent(s): 46bef1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -34
app.py CHANGED
@@ -1,49 +1,55 @@
1
- import google.generativeai as palm
2
- import os
3
  import gradio as gr
4
- import random
5
  import time
 
 
6
  palm.configure(api_key=os.environ.get("palm_key"))
7
 
8
  defaults = {
9
- 'model': 'models/chat-bison-001',
10
- 'temperature': 0.25,
11
- 'candidate_count': 1,
12
- 'top_k': 40,
13
- 'top_p': 0.95,
14
  }
15
- context = "Your a computer failure assitant"
 
 
16
  examples = [
17
- [
18
- "Hey my computer is broken",
19
- "Hey what is the issue with your computer?"
20
- ]
21
  ]
22
- messages = []
23
- messages.append("NEXT REQUEST")
 
24
  response = palm.chat(
25
- **defaults,
26
- context=context,
27
- examples=examples,
28
- messages=messages
29
  )
30
 
31
 
32
- with gr.Blocks() as demo:
33
- chatbot = gr.Chatbot()
34
- msg = gr.Textbox()
35
- clear = gr.ClearButton([msg, chatbot])
 
 
 
 
 
 
36
 
37
- def respond(response, messages):
38
- bot_message = palm.chat(
39
- **defaults,
40
- context=context,
41
- examples=examples,
42
- messages=messages
43
- )
44
- time.sleep(2)
45
- return "", messages
46
 
47
- msg.submit(respond, [msg, chatbot], [msg, chatbot])
 
 
 
 
 
 
48
 
49
- demo.launch()
 
 
 
1
  import gradio as gr
2
+ import os
3
  import time
4
+ from google.generativeai import palm
5
+
6
  palm.configure(api_key=os.environ.get("palm_key"))
7
 
8
  defaults = {
9
+ 'model': 'models/chat-bison-001',
10
+ 'temperature': 0.25,
11
+ 'candidate_count': 1,
12
+ 'top_k': 40,
13
+ 'top_p': 0.95,
14
  }
15
+
16
+ context = "You're a computer failure assistant"
17
+
18
  examples = [
19
+ [
20
+ "Hey my computer is broken",
21
+ "Hey, what is the issue with your computer?"
22
+ ]
23
  ]
24
+
25
+ messages = ["NEXT REQUEST"]
26
+
27
  response = palm.chat(
28
+ **defaults,
29
+ context=context,
30
+ examples=examples,
31
+ messages=messages
32
  )
33
 
34
 
35
+ def respond(msg):
36
+ messages.append(msg)
37
+ bot_message = palm.chat(
38
+ **defaults,
39
+ context=context,
40
+ examples=examples,
41
+ messages=messages
42
+ )
43
+ time.sleep(2)
44
+ return bot_message['message'], messages
45
 
 
 
 
 
 
 
 
 
 
46
 
47
+ iface = gr.Interface(
48
+ fn=respond,
49
+ inputs="text",
50
+ outputs="text",
51
+ title="Chatbot",
52
+ description="Interact with a chatbot."
53
+ )
54
 
55
+ iface.launch()