stale2000 commited on
Commit
7b664dc
1 Parent(s): e78db75

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[ ]:
5
+
6
+
7
+ import os
8
+ import openai
9
+ import gradio as gr
10
+
11
+ openai.api_key = "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"
12
+ start_sequence = "\nAI:"
13
+ restart_sequence = "\nHuman: "
14
+
15
+ def predict(input,initial_prompt, history=[]):
16
+
17
+ s = list(sum(history, ()))
18
+ s.append(input)
19
+ # initial_prompt="The following is a conversation with an AI movie recommendation assistant. The assistant is helpful, creative, clever, and very friendly.Along with movie recommendation it also talks about general topics"
20
+ # \n\nHuman: Hello, who are you?\nAI: I am an AI created by OpenAI. How can I help you today?\nHuman: "
21
+ response = openai.Completion.create(
22
+ model="text-davinci-003",
23
+ prompt= initial_prompt + "\n" + str(s),
24
+ temperature=0.9,
25
+ max_tokens=150,
26
+ top_p=1,
27
+ frequency_penalty=0,
28
+ presence_penalty=0.6,
29
+ stop=[" Human:", " AI:"])
30
+ # tokenize the new input sentence
31
+ response2 = response["choices"][0]["text"]
32
+ history.append((input, response2))
33
+
34
+ return history, history
35
+
36
+
37
+ gr.Interface(fn=predict,
38
+ inputs=["text","text",'state'],
39
+
40
+ outputs=["chatbot",'state']).launch()
41
+