Chickensyuh commited on
Commit
baaa7ac
·
1 Parent(s): 8b0132a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+ import gradio as gr
4
+
5
+ openai.api_key = "sk-00qmWbh6CPEJAHbT3BlbkFJLbkcfagm3tLjWZ9ukrr4"
6
+
7
+ start_sequence = "\nAI:"
8
+ restart_sequence = "\nHuman:"
9
+
10
+ def predict(input, history=[]):
11
+ s = list(sum(history, ()))
12
+ s.append(input)
13
+
14
+ response = openai.Completion.create(
15
+ model="text-davinci-003"
16
+ prompt=str(s),
17
+ max_tokens = 1050,
18
+ temperature = 0.9,
19
+ top_p = 1,
20
+ frequency_penalty=0,
21
+ presence_penalty=0.6,
22
+ )
23
+
24
+ response2 = response["choices"][0]["text"]
25
+ history.append((input, response2))
26
+
27
+ fr.Interface(fn=predict,
28
+ inputs="text",'state'),
29
+ outputs=["chatbot",'state']).launch()
30
+
31
+
32
+ #def get_model_reply(user_input, context=[]):
33
+ # context+=[user_input]
34
+
35
+ # completion = openai.Completion.create(
36
+ # engine="gpt-3.5-turbo", # one of the most capable models available
37
+ # prompt='\\n'.join([f"I am {role}.", *context])[:4096],
38
+ # max_tokens = 1048,
39
+ # temperature = 0.9,
40
+ # top_p = 1,
41
+ # frequency_penalty=0,
42
+ # presence_penalty=0.6,
43
+ # )
44
+
45
+ # append response to context
46
+ # response = completion.choices[0].text.strip('\\n')
47
+ # context += [response]
48
+
49
+ # list of (user, bot) responses. We will use this format later
50
+ # responses = [(u,b) for u,b in zip(context[::2], context[1::2])]
51
+
52
+ # return responses, context
53
+ # ```
54
+ # defines a basic dialog interface using Gradio
55
+ #with gr.Blocks() as dialog_app:
56
+ # chatbot = gr.Chatbot() # dedicated "chatbot" component
57
+ # state = gr.State([]) # session state that persists across multiple submits
58
+
59
+ # with gr.Row():
60
+ # txt = gr.Textbox(
61
+ # show_label=False,
62
+ # placeholder="Enter text and press enter"
63
+ # ).style(container=False)
64
+
65
+ # txt.submit(get_model_reply, [txt, state], [chatbot, state])
66
+
67
+ #dialog_app.launch()