abhishekt commited on
Commit
11ef4ab
·
1 Parent(s): c8f7d11
Files changed (1) hide show
  1. app.py +38 -13
app.py CHANGED
@@ -1,18 +1,43 @@
1
  import os
2
  import openai
 
 
 
3
  openai.api_key = os.environ["api"]
4
 
5
- import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- def generate_blog(topic):
8
- response = openai.Completion.create(
9
- engine="gpt-3.5-turbo",
10
- messages=[
11
- {"role": "system", "content": "You are a helpful assistant."},
12
- {"role": "user", "{topic}"},
13
- ]
14
- )
15
- return response['content'][0]['text']
16
-
17
- iface = gr.Interface(fn=generate_blog, inputs='text', outputs='text')
18
- iface.launch()
 
1
  import os
2
  import openai
3
+ import gradio as gr
4
+ import transformers
5
+
6
  openai.api_key = os.environ["api"]
7
 
8
+ generator = transformers.pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B")
9
+
10
+ def generateBlogTopics(prompt1):
11
+ response = generator("Generate blog topics on: {}. \n \n 1. ".format(prompt1), max_length=100, do_sample=True, temperature=0.7)[0]["generated_text"]
12
+ return response
13
+
14
+ def generateBlogSections(prompt1):
15
+ response = generator("Expand the blog title in to high level blog sections: {} \n\n- Introduction: ".format(prompt1), max_length=100, do_sample=True, temperature=0.6)[0]["generated_text"]
16
+ return response
17
+
18
+ def blogSectionExpander(prompt1):
19
+ response = generator("Expand the blog section in to a detailed professional, witty and clever explanation.\n\n {}".format(prompt1), max_length=400, do_sample=True, temperature=0.7)[0]["generated_text"]
20
+ return response
21
+
22
+ input_text = gr.inputs.Textbox(lines=5, label="Enter prompt text here:")
23
+
24
+ title_section_output = gr.outputs.Textbox(label="Title & Sections")
25
+ section_expander_output = gr.outputs.Textbox(label="Section Expander")
26
+
27
+ gr.Interface(
28
+ [generateBlogTopics, generateBlogSections],
29
+ inputs=input_text,
30
+ outputs=title_section_output,
31
+ title="Blog Title & Sections Generator",
32
+ description="Generate high level sections for your blog topic",
33
+ live=False
34
+ ).launch(share=True)
35
 
36
+ gr.Interface(
37
+ blogSectionExpander,
38
+ inputs=input_text,
39
+ outputs=section_expander_output,
40
+ title="Blog Section Expander",
41
+ description="Expand your blog sections with professional and clever explanation",
42
+ live=False
43
+ ).launch(share=True)