File size: 737 Bytes
5d1e1fc
056acc5
 
5d1e1fc
056acc5
 
 
5d1e1fc
056acc5
 
 
 
 
5d1e1fc
056acc5
5d1e1fc
056acc5
 
1ed2374
056acc5
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
import torch
from transformers import pipeline

# Load the GPT-2 model
device = 0 if torch.cuda.is_available() else -1
generator = pipeline("text-generation", model="gpt2", device=device)

# Function to generate blog
def generate_blog(topic):
    prompt = f"Write a detailed blog on the topic: {topic}\n\n"
    result = generator(prompt, max_length=250, do_sample=True, temperature=0.7)
    return result[0]["generated_text"]

# Gradio Interface
iface = gr.Interface(
    fn=generate_blog,
    inputs=gr.Textbox(label="Enter Blog Topic"),
    outputs=gr.Textbox(label="Generated Blog", lines=30),
    title="GPT-2 Blog Generator",
    description="Generate a short blog using GPT-2 pretrained model"
)

iface.launch()