Spaces:
Runtime error
Runtime error
Duplicate from zachriek/chatgpt-clone
Browse filesCo-authored-by: Muhammad Zachrie Kurniawan <[email protected]>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +53 -0
- requirements.txt +3 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Chatgpt Clone
|
3 |
+
emoji: 📚
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.15.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: zachriek/chatgpt-clone
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import openai
|
3 |
+
import gradio as gr
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
load_dotenv()
|
7 |
+
|
8 |
+
openai.api_key = os.getenv("API_KEY")
|
9 |
+
|
10 |
+
start_sequence = "\nAI: "
|
11 |
+
restart_sequence = "\nHuman: "
|
12 |
+
|
13 |
+
prompt = "The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.\n\nHuman: Hello, who are you?\nAI: I am an AI created by OpenAI. How can I help you today?\nHuman: "
|
14 |
+
|
15 |
+
|
16 |
+
def openai_create(prompt):
|
17 |
+
response = openai.Completion.create(
|
18 |
+
model="text-davinci-003",
|
19 |
+
prompt=prompt,
|
20 |
+
temperature=0.9,
|
21 |
+
max_tokens=150,
|
22 |
+
top_p=1,
|
23 |
+
frequency_penalty=0,
|
24 |
+
presence_penalty=0,
|
25 |
+
stop=[" Human:", " AI:"]
|
26 |
+
)
|
27 |
+
return response.choices[0].text
|
28 |
+
|
29 |
+
|
30 |
+
def chatgpt_clone(input, history):
|
31 |
+
history = history or []
|
32 |
+
s = list(sum(history, ()))
|
33 |
+
s.append(input)
|
34 |
+
inp = ' '.join(s)
|
35 |
+
output = openai_create(inp)
|
36 |
+
history.append((input, output))
|
37 |
+
return history, history
|
38 |
+
|
39 |
+
|
40 |
+
block = gr.Blocks()
|
41 |
+
|
42 |
+
|
43 |
+
with block:
|
44 |
+
gr.Markdown("""<h1><center>Build Your Own ChatGPT with OpenAI API & Gradio</center></h1>
|
45 |
+
""")
|
46 |
+
chatbot = gr.Chatbot().style(color_map=("#CE6400", "#0b0f19"))
|
47 |
+
message = gr.Textbox(placeholder=prompt)
|
48 |
+
state = gr.State()
|
49 |
+
submit = gr.Button("SEND", variant="primary")
|
50 |
+
submit.click(chatgpt_clone, inputs=[
|
51 |
+
message, state], outputs=[chatbot, state])
|
52 |
+
|
53 |
+
block.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
openai
|
2 |
+
gradio
|
3 |
+
python-dotenv
|