Maaz66 commited on
Commit
7aef422
1 Parent(s): 1cea1c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -5
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
- inputs = gr.inputs.Textbox(placeholder="Enter prompt for GPT-3 Completion")
28
- outputs = gr.outputs.Textbox()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- interface = gr.Interface(GPT3_Completion, inputs, outputs)
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()