File size: 1,807 Bytes
cb07ab0
 
 
 
 
 
 
 
99d207a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
812dd54
cb07ab0
70b1905
138f215
70b1905
d2e9f68
 
 
 
 
 
 
 
99d207a
d2e9f68
 
 
99d207a
 
 
 
 
 
 
cb07ab0
99d207a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# from transformers import pipeline

# generator = pipeline("text-generation", model="gpt2")

# def generate_blog(topic):
#     return generator(f"Write a blog on: {topic}", max_length=200)[0]["generated_text"]


# from transformers import pipeline
# import gradio as gr

# # Load the model
# generator = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1")

# # Define your function
# def generate_text(prompt):
#     result = generator(prompt, max_length=100, num_return_sequences=1, do_sample=True, 
#     temperature=0.7, 
#     top_p=0.9,)
#     return result[0]["generated_text"]

# # Create Gradio interface
# iface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="Text Generator with GPT-2")

# # βœ… This line is required to actually launch the app on Hugging Face Spaces
# iface.launch()



from transformers import pipeline
import gradio as gr

generator = pipeline("text-generation", model="EleutherAI/gpt-neo-125M")

def clean_topic(topic):
    topic = topic.lower()
    if "write a blog on" in topic:
        topic = topic.replace("write a blog on", "").strip()
    elif "write a blog about" in topic:
        topic = topic.replace("write a blog about", "").strip()
    return topic.capitalize()

def generate_blog(topic):
    topic = clean_topic(topic)
    if not topic:
        return "Please provide a topic."
    prompt = f"""
    Write a detailed and engaging blog post about "{topic}".
    Include an introduction, 2–3 subheadings with paragraphs, and a conclusion.
    Make it informative and conversational.
    """
    result = generator(prompt, max_length=700, do_sample=True, temperature=0.7, top_p=0.9)
    return result[0]['generated_text']

gr.Interface(fn=generate_blog, inputs="text", outputs="text", title="AI Blog Writer").launch()