Pooja P commited on
Commit
d4525b3
·
1 Parent(s): ae4f82a

added app.py and requirments file

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from transformers import pipeline
3
+ import gradio as gr
4
+
5
+ # Use the token from environment variable (secret)
6
+ token = os.environ.get("OPENAI_API_KEY")
7
+ generator = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", token=token)
8
+
9
+ def clean_topic(topic):
10
+ topic = topic.lower()
11
+ if "write a blog on" in topic:
12
+ topic = topic.replace("write a blog on", "").strip()
13
+ elif "write a blog about" in topic:
14
+ topic = topic.replace("write a blog about", "").strip()
15
+ return topic.capitalize()
16
+
17
+ def generate_blog(topic):
18
+ topic = clean_topic(topic)
19
+ prompt = f"""
20
+ Write a detailed and engaging blog post about "{topic}".
21
+ Include an introduction, 2–3 subheadings with paragraphs, and a conclusion.
22
+ Make it informative and conversational.
23
+ """
24
+ result = generator(prompt, max_length=700, do_sample=True, temperature=0.7, top_p=0.9)
25
+ return result[0]['generated_text']
26
+
27
+ gr.Interface(fn=generate_blog, inputs="text", outputs="text", title="AI Blog Writer").launch()
28
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ gradio
3
+ torch
4
+ openai