pratikshahp commited on
Commit
6bdc5d4
·
verified ·
1 Parent(s): ff38f6e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
+
5
+ # Load the model and tokenizer
6
+ model_name = "meta-llama/Meta-Llama-Guard-2-8B"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name)
9
+
10
+ # Function to generate blog content
11
+ def generate_blog(topic, keywords):
12
+ prompt_template = f"""
13
+ You are a technical content writer. Write a detailed and informative blog on the following topic.
14
+
15
+ Topic: {topic}
16
+
17
+ Keywords: {keywords}
18
+
19
+ Make sure the blog covers the following sections:
20
+ 1. Introduction
21
+ 2. Detailed Explanation
22
+ 3. Examples
23
+ 4. Conclusion
24
+
25
+ Blog:
26
+ """
27
+
28
+ inputs = tokenizer(prompt_template, return_tensors="pt", max_length=512, truncation=True)
29
+ outputs = model.generate(inputs.input_ids, max_length=800, num_return_sequences=1, temperature=0.7)
30
+ blog_content = tokenizer.decode(outputs[0], skip_special_tokens=True)
31
+
32
+ return blog_content
33
+
34
+ # Gradio interface
35
+ iface = gr.Interface(
36
+ fn=generate_blog,
37
+ inputs=[
38
+ gr.Textbox(lines=2, placeholder="Enter the blog topic", label="Blog Topic"),
39
+ gr.Textbox(lines=2, placeholder="Enter keywords (comma-separated)", label="Keywords")
40
+ ],
41
+ outputs=gr.Textbox(label="Generated Blog Content"),
42
+ title="Technical Blog Generator",
43
+ description="Generate a detailed technical blog by providing a topic and relevant keywords."
44
+ )
45
+
46
+ if __name__ == "__main__":
47
+ iface.launch()