Spaces:
Runtime error
Runtime error
Antoine245
commited on
Commit
·
e648b17
1
Parent(s):
46bef1e
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,55 @@
|
|
1 |
-
import google.generativeai as palm
|
2 |
-
import os
|
3 |
import gradio as gr
|
4 |
-
import
|
5 |
import time
|
|
|
|
|
6 |
palm.configure(api_key=os.environ.get("palm_key"))
|
7 |
|
8 |
defaults = {
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
}
|
15 |
-
|
|
|
|
|
16 |
examples = [
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
]
|
22 |
-
|
23 |
-
messages
|
|
|
24 |
response = palm.chat(
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
)
|
30 |
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
|
|
|
|
|
|
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()
|