Spaces:
Runtime error
Runtime error
pyresearch
commited on
Commit
·
a39b2e4
1
Parent(s):
4fab249
Delete app.py
Browse files
app.py
DELETED
@@ -1,67 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
|
3 |
-
import openai
|
4 |
-
import gradio as gr
|
5 |
-
|
6 |
-
openai.api_key = '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'
|
7 |
-
#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
|
8 |
-
|
9 |
-
def clean_textbox(*args):
|
10 |
-
n = len(args)
|
11 |
-
return [""] * n
|
12 |
-
|
13 |
-
|
14 |
-
class ChatGPT:
|
15 |
-
def __init__(self):
|
16 |
-
self.messages = [{'role': 'system', 'content': "You are now a very useful maid assistant! If you have a question you can't answer, please reply with As a classy, I can't answer this question"}]
|
17 |
-
|
18 |
-
def reset(self, *args):
|
19 |
-
self.messages = [{'role': 'system', 'content': "You are now a very useful maid assistant! If you have a question you can't answer, please reply with As a classy, I can't answer this question"}]
|
20 |
-
return clean_textbox(*args)
|
21 |
-
|
22 |
-
def chat(self, prompt):
|
23 |
-
self.messages.append({"role": "user", "content": prompt})
|
24 |
-
completion = openai.ChatCompletion.create(
|
25 |
-
model="gpt-3.5-turbo",
|
26 |
-
messages=self.messages,
|
27 |
-
temperature=0.7
|
28 |
-
)
|
29 |
-
res_msg = completion.choices[0].message["content"].strip()
|
30 |
-
self.messages.append({"role": "assistant", "content": res_msg})
|
31 |
-
return res_msg
|
32 |
-
|
33 |
-
|
34 |
-
if __name__ == '__main__':
|
35 |
-
my_chatgpt = ChatGPT()
|
36 |
-
with gr.Blocks(title="POULTA INC ChatGPT") as demo:
|
37 |
-
gr.Markdown('''
|
38 |
-
# ChatGPT
|
39 |
-
''')
|
40 |
-
with gr.Row():
|
41 |
-
with gr.Column(scale=9):
|
42 |
-
prompt = gr.Text(label='ChatGPT_Prompt', show_label=False, lines=3,
|
43 |
-
placeholder='ChatGPT Prompt')
|
44 |
-
res = gr.Text(label='ChatGPT_result', show_label=False, lines=3,
|
45 |
-
placeholder='chatgpt results')
|
46 |
-
|
47 |
-
with gr.Column(scale=1):
|
48 |
-
btn_gen = gr.Button(value="send", variant='primary')
|
49 |
-
btn_clear = gr.Button(value="restart chat")
|
50 |
-
|
51 |
-
gr.Examples([
|
52 |
-
["What is Poulta Inc?"],
|
53 |
-
["what is Poulta inc doing?"],
|
54 |
-
["Poulta inc Bring real-time central monitoring to your farms"]],
|
55 |
-
inputs=[prompt],
|
56 |
-
outputs=[res],
|
57 |
-
fn=my_chatgpt.chat,
|
58 |
-
cache_examples=False)
|
59 |
-
|
60 |
-
btn_gen.click(fn=my_chatgpt.chat, inputs=prompt,
|
61 |
-
outputs=res)
|
62 |
-
btn_clear.click(fn=my_chatgpt.reset,
|
63 |
-
inputs=[prompt, res],
|
64 |
-
outputs=[prompt, res])
|
65 |
-
|
66 |
-
demo.queue()
|
67 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|