File size: 1,482 Bytes
6bdc5d4
 
 
cf56f61
baa8f63
bcf654a
 
6722d35
 
bcf654a
7ff7916
 
6bdc5d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bcf654a
 
 
6bdc5d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bcf654a
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
from dotenv import load_dotenv
import os

# Load environment variables
load_dotenv()

# Load the model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b")
model = AutoModelForCausalLM.from_pretrained("google/gemma-2b")


# Function to generate blog content
def generate_blog(topic, keywords):
    prompt_template = f"""
    You are a technical content writer. Write a detailed and informative blog on the following topic.
    Topic: {topic}
    Keywords: {keywords}
    Make sure the blog covers the following sections:
    1. Introduction
    2. Detailed Explanation
    3. Examples
    4. Conclusion
    
    Blog:
    """
    input_ids = tokenizer(prompt_template, return_tensors="pt")
    outputs = model.generate(**input_ids)
    blog_content = tokenizer.decode(outputs[0])
    
    return blog_content

# Gradio interface
iface = gr.Interface(
    fn=generate_blog,
    inputs=[
        gr.Textbox(lines=2, placeholder="Enter the blog topic", label="Blog Topic"),
        gr.Textbox(lines=2, placeholder="Enter keywords (comma-separated)", label="Keywords")
    ],
    outputs=gr.Textbox(label="Generated Blog Content"),
    title="Technical Blog Generator",
    description="Generate a detailed technical blog by providing a topic and relevant keywords."
)

if __name__ == "__main__":
    iface.launch(share=True)  # Set share=True to generate a public link