dtrejopizzo commited on
Commit
cdcdde4
·
1 Parent(s): 8a7777a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -20
app.py CHANGED
@@ -1,22 +1,25 @@
 
1
  import gradio as gr
2
- from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- generator = pipeline('text-generation', model='gpt2')
5
-
6
- def generate(text):
7
- result = generator(text, max_length=30, num_return_sequences=1)
8
- return result[0]["generated_text"]
9
-
10
- examples = [
11
- ["The Moon's orbit around Earth has"],
12
- ["The smooth Borealis basin in the Northern Hemisphere covers 40%"],
13
- ]
14
-
15
- demo = gr.Interface(
16
- fn=generate,
17
- inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
18
- outputs=gr.outputs.Textbox(label="Generated Text"),
19
- examples=examples
20
- )
21
-
22
- demo.launch()
 
1
+ import openai
2
  import gradio as gr
3
+ openai.api_key ='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'
4
+ def openai_chat(prompt):
5
+ completions = openai.Completion.create(
6
+ engine="text-davinci-003",
7
+ prompt=prompt+"The following is the prompt from teacher working in canvas infrastructure",
8
+ max_tokens=1024,
9
+ n=1,
10
+ temperature=0.5,
11
+ frequency_penalty=0,
12
+ presence_penalty=0.6,
13
+ stop=[" Human:", " AI:"]
14
+ )
15
 
16
+ message = completions.choices[0].text
17
+ return message.strip()
18
+ def chatbot(input, history=[]):
19
+ output = openai_chat(input)
20
+ history.append((input, output))
21
+ return history, history
22
+ gr.Interface(fn = chatbot,
23
+ inputs = ["text",'state'],
24
+ outputs = ["chatbot",'state'],
25
+ allow_flagging="manual").launch()