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