Spaces:
Running
Running
hoshingakag
commited on
Commit
•
7f82a6a
1
Parent(s):
3a32249
Delete app.py.bk
Browse files
app.py.bk
DELETED
@@ -1,104 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import time
|
3 |
-
import gradio as gr
|
4 |
-
import google.generativeai as genai
|
5 |
-
|
6 |
-
# Credentials
|
7 |
-
genai.configure(api_key=os.getenv('PALM_API_KEY'))
|
8 |
-
|
9 |
-
# Gradio
|
10 |
-
title = '🦒Playground w/ Google PaLM v2'
|
11 |
-
description = """Click below tab and start with your message"""
|
12 |
-
|
13 |
-
def generate_text(prompt: str):
|
14 |
-
response = genai.generate_text(prompt=prompt)
|
15 |
-
return response.result
|
16 |
-
|
17 |
-
chat_defaults = {
|
18 |
-
'model': 'models/chat-bison-001',
|
19 |
-
'temperature': 0.25,
|
20 |
-
'candidate_count': 1,
|
21 |
-
'top_k': 40,
|
22 |
-
'top_p': 0,
|
23 |
-
}
|
24 |
-
|
25 |
-
chat_messages = []
|
26 |
-
|
27 |
-
def generate_chat(prompt: str):
|
28 |
-
context = "You are an intelligent chatbot powered by biggest technology company."
|
29 |
-
chat_messages.append(prompt)
|
30 |
-
response = genai.chat(
|
31 |
-
**chat_defaults,
|
32 |
-
context=context,
|
33 |
-
messages=chat_messages
|
34 |
-
)
|
35 |
-
chat_messages.append(response.last)
|
36 |
-
return response.last
|
37 |
-
|
38 |
-
with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
|
39 |
-
|
40 |
-
gr.Markdown(
|
41 |
-
f"""
|
42 |
-
# {title}
|
43 |
-
## {description}
|
44 |
-
""")
|
45 |
-
|
46 |
-
with gr.Tab('Just Text'):
|
47 |
-
chatbot = gr.Chatbot(height=600)
|
48 |
-
msg = gr.Textbox()
|
49 |
-
clear = gr.Button("Clear")
|
50 |
-
accordion = gr.Accordion("Generation History")
|
51 |
-
|
52 |
-
def record(history):
|
53 |
-
return history
|
54 |
-
|
55 |
-
def user(user_message, history):
|
56 |
-
return "", history + [[user_message, None]]
|
57 |
-
|
58 |
-
def bot(history):
|
59 |
-
bot_message = generate_text(history[-1][0])
|
60 |
-
history[-1][1] = ""
|
61 |
-
for character in bot_message:
|
62 |
-
history[-1][1] += character
|
63 |
-
time.sleep(0.01)
|
64 |
-
yield history
|
65 |
-
|
66 |
-
msg.submit(record, accordion, accordion)
|
67 |
-
|
68 |
-
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
69 |
-
bot, chatbot, chatbot
|
70 |
-
)
|
71 |
-
|
72 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
73 |
-
|
74 |
-
# for generation in store:
|
75 |
-
# gr.Markdown(f"Query: {generation[0]}\nAnswer: {generation[1]}")
|
76 |
-
|
77 |
-
with gr.Tab('Just Chat'):
|
78 |
-
chatbot = gr.Chatbot(height=600)
|
79 |
-
msg = gr.Textbox()
|
80 |
-
clear = gr.Button("Clear")
|
81 |
-
|
82 |
-
def user(user_message, history):
|
83 |
-
return "", history + [[user_message, None]]
|
84 |
-
|
85 |
-
def bot(history):
|
86 |
-
bot_message = generate_chat(history[-1][0])
|
87 |
-
history[-1][1] = ""
|
88 |
-
for character in bot_message:
|
89 |
-
history[-1][1] += character
|
90 |
-
time.sleep(0.01)
|
91 |
-
yield history
|
92 |
-
|
93 |
-
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
94 |
-
bot, chatbot, chatbot
|
95 |
-
)
|
96 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
97 |
-
|
98 |
-
gr.Markdown(
|
99 |
-
f"""
|
100 |
-
Testing by __G__
|
101 |
-
""")
|
102 |
-
|
103 |
-
demo.queue()
|
104 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|