V7
Browse files
app.py
CHANGED
@@ -3,20 +3,16 @@
|
|
3 |
import gradio as gr
|
4 |
import openai
|
5 |
import re
|
6 |
-
from transformers import pipeline, set_seed
|
7 |
|
8 |
# Set up OpenAI API credentials
|
9 |
openai.api_key = os.environ["api"]
|
10 |
|
11 |
-
# Set up Hugging Face pipeline for summarization
|
12 |
-
summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base")
|
13 |
-
|
14 |
# Define the function that generates the blog article
|
15 |
def generate_article(topic):
|
16 |
# Use OpenAI's GPT-3 to generate the article
|
17 |
prompt = f"Write a blog post about {topic} with 5 different sections."
|
18 |
response = openai.Completion.create(
|
19 |
-
engine="davinci",
|
20 |
prompt=prompt,
|
21 |
max_tokens=2048,
|
22 |
n=1,
|
@@ -33,16 +29,10 @@ def generate_article(topic):
|
|
33 |
section_length = len(article) // 5
|
34 |
sections = [article[i:i+section_length] for i in range(0, len(article), section_length)]
|
35 |
|
36 |
-
#
|
37 |
-
set_seed(42)
|
38 |
-
|
39 |
-
# Summarize each section to generate subheadings
|
40 |
-
subheadings = [summarizer(section, max_length=30, min_length=10, do_sample=False)[0]['summary_text'] for section in sections]
|
41 |
-
|
42 |
-
# Combine the sections and subheadings into a formatted blog post
|
43 |
blog_post = f"# {topic}\n\n"
|
44 |
for i in range(5):
|
45 |
-
blog_post += f"## {
|
46 |
|
47 |
return blog_post
|
48 |
|
@@ -52,8 +42,9 @@ iface = gr.Interface(
|
|
52 |
inputs=gr.inputs.Textbox("Enter a topic for your blog post"),
|
53 |
outputs=gr.outputs.HTML(),
|
54 |
title="Blog Post Generator",
|
55 |
-
description="Generate a blog post on a given topic with 5 different sections.",
|
56 |
)
|
57 |
|
58 |
# Launch the interface
|
59 |
iface.launch(share=True)
|
|
|
|
3 |
import gradio as gr
|
4 |
import openai
|
5 |
import re
|
|
|
6 |
|
7 |
# Set up OpenAI API credentials
|
8 |
openai.api_key = os.environ["api"]
|
9 |
|
|
|
|
|
|
|
10 |
# Define the function that generates the blog article
|
11 |
def generate_article(topic):
|
12 |
# Use OpenAI's GPT-3 to generate the article
|
13 |
prompt = f"Write a blog post about {topic} with 5 different sections."
|
14 |
response = openai.Completion.create(
|
15 |
+
engine="text-davinci-002",
|
16 |
prompt=prompt,
|
17 |
max_tokens=2048,
|
18 |
n=1,
|
|
|
29 |
section_length = len(article) // 5
|
30 |
sections = [article[i:i+section_length] for i in range(0, len(article), section_length)]
|
31 |
|
32 |
+
# Combine the sections into a formatted blog post
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
blog_post = f"# {topic}\n\n"
|
34 |
for i in range(5):
|
35 |
+
blog_post += f"## Section {i+1}\n\n{sections[i]}\n\n"
|
36 |
|
37 |
return blog_post
|
38 |
|
|
|
42 |
inputs=gr.inputs.Textbox("Enter a topic for your blog post"),
|
43 |
outputs=gr.outputs.HTML(),
|
44 |
title="Blog Post Generator",
|
45 |
+
description="Generate a blog post on a given topic with 5 different sections using OpenAI's GPT-3 text model.",
|
46 |
)
|
47 |
|
48 |
# Launch the interface
|
49 |
iface.launch(share=True)
|
50 |
+
|