Mangara01 commited on
Commit
79bf4bb
·
1 Parent(s): 7ab8869

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+
4
+ def initialize_openai(api_key):
5
+ openai.api_key = api_key
6
+
7
+ def generate_text(api_key, direction, paragraphs=5, max_tokens=400):
8
+ initialize_openai(api_key)
9
+ response = openai.Completion.create(
10
+ engine="text-davinci-003",
11
+ prompt=direction,
12
+ max_tokens=max_tokens * paragraphs,
13
+ temperature=0.7,
14
+ stop=None,
15
+ n=paragraphs,
16
+ )
17
+ return response.choices[0].text.strip()
18
+
19
+ iface = gr.Interface(
20
+ fn=generate_text,
21
+ inputs=["text", "text"],
22
+ outputs="text",
23
+ title="OpenAI Text Generator",
24
+ description="Generate text based on a given direction",
25
+ live=False
26
+ )
27
+
28
+ iface.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai
2
+ gradio