Upload 2 files
Browse files- app.py +39 -0
- requirements.txt +8 -0
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the GPT-2 News Generation Model
|
| 5 |
+
model_name = "AventIQ-AI/gpt2-news-article-generation"
|
| 6 |
+
generator = pipeline("text-generation", model=model_name)
|
| 7 |
+
|
| 8 |
+
# Predefined headline suggestions
|
| 9 |
+
headline_suggestions = [
|
| 10 |
+
"Breaking: Stock Market Hits Record High",
|
| 11 |
+
"Scientists Discover New Treatment for Alzheimer's",
|
| 12 |
+
"Tech Giants Compete in AI Race",
|
| 13 |
+
"Severe Weather Warnings Issued Across the Country",
|
| 14 |
+
"New Law Passed to Improve Cybersecurity Standards"
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
def generate_news_article(headline, max_length=250):
|
| 18 |
+
"""Generate a news article based on the given headline."""
|
| 19 |
+
response = generator(headline, max_length=max_length, num_return_sequences=1)
|
| 20 |
+
return response[0]["generated_text"]
|
| 21 |
+
|
| 22 |
+
# Create Gradio UI
|
| 23 |
+
with gr.Blocks(theme="default") as demo:
|
| 24 |
+
gr.Markdown("## 📰 GPT-2 News Article Generator")
|
| 25 |
+
gr.Markdown("🔍 Enter a **news headline**, and the model will generate a news article based on it.")
|
| 26 |
+
|
| 27 |
+
headline_input = gr.Textbox(placeholder="Enter a news headline...", label="News Headline")
|
| 28 |
+
suggestion_dropdown = gr.Dropdown(choices=headline_suggestions, label="💡 Select a Sample Headline (Optional)")
|
| 29 |
+
generate_button = gr.Button("📝 Generate Article")
|
| 30 |
+
output_box = gr.Textbox(label="Generated News Article", interactive=False)
|
| 31 |
+
|
| 32 |
+
# Function to update input field with selected suggestion
|
| 33 |
+
def update_headline(suggestion):
|
| 34 |
+
return suggestion
|
| 35 |
+
|
| 36 |
+
suggestion_dropdown.change(update_headline, inputs=[suggestion_dropdown], outputs=[headline_input])
|
| 37 |
+
generate_button.click(generate_news_article, inputs=[headline_input], outputs=[output_box])
|
| 38 |
+
|
| 39 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|
| 3 |
+
gradio
|
| 4 |
+
sentencepiece
|
| 5 |
+
torchvision
|
| 6 |
+
huggingface_hub
|
| 7 |
+
pillow
|
| 8 |
+
numpy
|