Daniton commited on
Commit
7d7a869
·
1 Parent(s): 59a097f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+
4
+ # Authenticate with OpenAI API
5
+ openai.api_key = "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"
6
+
7
+ # Define GPT-2 model
8
+ model_engine = "text-davinci-002"
9
+ prompt = "Write a short paragraph about a topic of your choice:"
10
+
11
+ def generate_text(prompt):
12
+ # Use GPT-2 to generate text based on user input
13
+ response = openai.Completion.create(
14
+ engine=model_engine,
15
+ prompt=prompt,
16
+ max_tokens=1024,
17
+ n=1,
18
+ stop=None,
19
+ temperature=0.5,
20
+ )
21
+ return response.choices[0].text
22
+
23
+ # Create Gradio interface
24
+ interface = gr.Interface(
25
+ generate_text,
26
+ inputs=gr.inputs.Textbox(prompt),
27
+ outputs=gr.outputs.Textbox(),
28
+ title="GPT-2 Text Generation",
29
+ )
30
+
31
+ # Launch the interface
32
+ interface.launch()