hidrometer
commited on
Commit
•
6dd6510
1
Parent(s):
04a3b15
Upload chatGPT.py
Browse files- chatGPT.py +45 -0
chatGPT.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import openai
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
YOUR_API_KEY = "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"
|
6 |
+
openai.api_key = YOUR_API_KEY
|
7 |
+
|
8 |
+
start_sequence = "\AI:"
|
9 |
+
restart_sequence = "\Human:"
|
10 |
+
|
11 |
+
prompt = "Ketik disini..."
|
12 |
+
|
13 |
+
def openai_create(prompt):
|
14 |
+
response = openai.Completion.create(
|
15 |
+
model = "text-davinci-003",
|
16 |
+
prompt = prompt,
|
17 |
+
temperature = 0.9,
|
18 |
+
max_tokens=150,
|
19 |
+
top_p=1,
|
20 |
+
frequency_penalty=0,
|
21 |
+
presence_penalty=0.6,
|
22 |
+
stop=[" Human:", " AI:"]
|
23 |
+
)
|
24 |
+
return response.choices[0].text
|
25 |
+
|
26 |
+
def chatgpt_clone(input, history):
|
27 |
+
history = history or []
|
28 |
+
s = list(sum(history, ()))
|
29 |
+
s.append(input)
|
30 |
+
inp = ' '.join(s)
|
31 |
+
output = openai_create(inp)
|
32 |
+
history.append((input, output))
|
33 |
+
return history, history
|
34 |
+
|
35 |
+
block = gr.Blocks()
|
36 |
+
|
37 |
+
with block:
|
38 |
+
gr.Markdown("""<h1><center>My chatGPT</center></h1>""")
|
39 |
+
chatbot = gr.Chatbot()
|
40 |
+
message = gr.Textbox(placeholder=prompt)
|
41 |
+
state = gr.State()
|
42 |
+
submit = gr.Button("KIRIM")
|
43 |
+
submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
|
44 |
+
|
45 |
+
block.launch(share=True, debug=True)
|