Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,20 @@ import gradio as gr
|
|
2 |
import openai
|
3 |
from googletrans import Translator
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def GPT3_Completion(prompt):
|
6 |
# translate the prompt to English
|
7 |
translator = Translator()
|
@@ -23,9 +37,26 @@ def GPT3_Completion(prompt):
|
|
23 |
|
24 |
return response_spanish
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
interface.launch()
|
|
|
2 |
import openai
|
3 |
from googletrans import Translator
|
4 |
|
5 |
+
import os
|
6 |
+
import openai
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
#if you have OpenAI API key as an environment variable, enable the below
|
10 |
+
#openai.api_key = os.getenv("OPENAI_API_KEY")
|
11 |
+
|
12 |
+
#if you have OpenAI API key as a string, enable the below
|
13 |
+
openai.api_key = "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"
|
14 |
+
|
15 |
+
start_sequence = "\nAI:"
|
16 |
+
restart_sequence = "\nHuman: "
|
17 |
+
|
18 |
+
prompt = "Imagination is the limit!!"
|
19 |
def GPT3_Completion(prompt):
|
20 |
# translate the prompt to English
|
21 |
translator = Translator()
|
|
|
37 |
|
38 |
return response_spanish
|
39 |
|
40 |
+
def chatgpt_clone(input, history):
|
41 |
+
history = history or []
|
42 |
+
s = list(sum(history, ()))
|
43 |
+
s.append(input)
|
44 |
+
inp = ' '.join(s)
|
45 |
+
output = GPT3_Completion(inp)
|
46 |
+
history.append((input, output))
|
47 |
+
return history, history
|
48 |
+
|
49 |
+
|
50 |
+
block = gr.Blocks()
|
51 |
+
|
52 |
+
|
53 |
+
with block:
|
54 |
+
gr.Markdown("""<h1><center>Chatbot with OpenAI API & Gradio</center></h1>
|
55 |
+
""")
|
56 |
+
chatbot = gr.Chatbot()
|
57 |
+
message = gr.Textbox(placeholder=prompt)
|
58 |
+
state = gr.State()
|
59 |
+
submit = gr.Button("SEND")
|
60 |
+
submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
|
61 |
|
62 |
+
block.launch()
|
|