mikaelbhai commited on
Commit
3bb7591
1 Parent(s): 7317f35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -69
app.py CHANGED
@@ -1,79 +1,25 @@
1
- import os
2
  import openai
3
  import gradio as gr
4
 
5
 
6
- openai.api_key = "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"
7
-
8
- start_sequence = "\nAI:"
9
- restart_sequence = "\nHuman: "
10
-
11
- 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: "
12
-
13
- def openai_create(prompt):
14
-
15
- response = openai.Completion.create(
16
- model="text-davinci-003",
17
- prompt=prompt,
18
- temperature=0.9,
19
- max_tokens=150,
20
- top_p=1,
21
- frequency_penalty=0,
22
- presence_penalty=0.6,
23
- stop=[" Human:", " AI:"]
24
  )
25
 
26
- return response.choices[0].text
27
-
28
- def send_message():
29
- input_text = message.value
30
- state["conversation_history"], _ = chatgpt_clone(input_text, state["conversation_history"])
31
- message.value = "" # clear the input textbox after sending the message
32
-
33
- submit = gr.Button("SEND", onclick=send_message)
34
-
35
- block = gr.Interface(
36
- fn=chatgpt_clone,
37
- inputs=["text", "text"],
38
- outputs=["text", "text"],
39
- inputs_layout="vertical",
40
- outputs_layout="vertical",
41
- title="bhAI",
42
- description="Talk to an AI assistant!",
43
- theme="compact",
44
- layout="vertical",
45
- article="The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.",
46
- examples=[
47
- ["Hello, who are you?", "I am an AI created by OpenAI. How can I help you today?"],
48
- ["What's the weather like?", "I'm not sure. Would you like me to look it up?"],
49
- ["What's your favorite color?", "I don't have a favorite color, but I like all the colors of the rainbow!"]
50
- ]
51
- )
52
 
53
- block.set_block(submit)
54
-
55
- block.launch()
56
-
57
- def chatgpt_clone(input, history):
58
- history = history or []
59
- s = list(sum(history, ()))
60
- s.append(input)
61
- inp = ' '.join(s)
62
- output = openai_create(inp)
63
  history.append((input, output))
64
  return history, history
65
 
66
-
67
- block = gr.Blocks()
68
-
69
-
70
- with block:
71
- gr.Markdown("""<h1><center>bhAI</center></h1>
72
- """)
73
- chatbot = gr.Chatbot()
74
- message = gr.Textbox(placeholder=prompt)
75
- state = gr.State()
76
- submit = gr.Button("SEND")
77
- submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
78
-
79
- block.launch(debug = True)
 
 
1
  import openai
2
  import gradio as gr
3
 
4
 
5
+ def openai_chat(prompt):
6
+ completions = openai.Completion.create(
7
+ engine="text-davinci-003",
8
+ prompt=prompt,
9
+ max_tokens=1024,
10
+ n=1,
11
+ temperature=0.5,
 
 
 
 
 
 
 
 
 
 
 
12
  )
13
 
14
+ message = completions.choices[0].text
15
+ return message.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ def chatbot(input, history=[]):
18
+ output = openai_chat(input)
 
 
 
 
 
 
 
 
19
  history.append((input, output))
20
  return history, history
21
 
22
+ gr.Interface(fn = GPTBhai,
23
+ inputs = ["text",'state'],
24
+ outputs = ["chatbot",'state']
25
+ title = "bhAI").launch(debug = True)