|
import gradio as gr |
|
from transformers import pipeline |
|
from diffusers import StableDiffusionPipeline |
|
import torch |
|
|
|
|
|
device = "cuda" if torch.cuda.is_available() else "cpu" |
|
|
|
text_generator = pipeline("text-generation", model="gpt2", device=device) |
|
summarizer = pipeline("summarization", model="facebook/bart-large-cnn", device=device) |
|
title_generator = pipeline("text2text-generation", model="fabiochiu/t5-small-medium-title-generation", device=device) |
|
|
|
|
|
stable_diffusion = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16) |
|
stable_diffusion.to(device) |
|
|
|
|
|
def generate_blog_post(query): |
|
|
|
article = text_generator(query, max_length=500, num_return_sequences=1)[0]['generated_text'] |
|
|
|
|
|
title = title_generator(article, max_length=30, num_return_sequences=1)[0]['generated_text'] |
|
|
|
|
|
cover_image = stable_diffusion(query, num_inference_steps=50, guidance_scale=7.5).images[0] |
|
|
|
|
|
summary = summarizer(article, max_length=100, min_length=30, do_sample=False)[0]['summary_text'] |
|
|
|
return title, article, cover_image, summary |
|
|
|
|
|
iface = gr.Interface( |
|
fn=generate_blog_post, |
|
inputs=gr.Textbox(lines=2, placeholder="Enter your blog post topic..."), |
|
outputs=[ |
|
gr.Textbox(label="Generated Title"), |
|
gr.Textbox(label="Generated Article"), |
|
gr.Image(label="Cover Image"), |
|
gr.Textbox(label="Article Summary") |
|
], |
|
title="Blog Post Generator", |
|
description="Enter a topic, and I'll generate a blog post with a title, cover image, and summary!" |
|
) |
|
|
|
|
|
iface.launch() |
|
|