Initial UI
Browse files- .gitignore +54 -0
- README.md +48 -7
- app.py +197 -0
- requirements.txt +4 -0
.gitignore
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
build/
|
| 8 |
+
develop-eggs/
|
| 9 |
+
dist/
|
| 10 |
+
downloads/
|
| 11 |
+
eggs/
|
| 12 |
+
.eggs/
|
| 13 |
+
lib/
|
| 14 |
+
lib64/
|
| 15 |
+
parts/
|
| 16 |
+
sdist/
|
| 17 |
+
var/
|
| 18 |
+
wheels/
|
| 19 |
+
*.egg-info/
|
| 20 |
+
.installed.cfg
|
| 21 |
+
*.egg
|
| 22 |
+
MANIFEST
|
| 23 |
+
|
| 24 |
+
# Virtual environments
|
| 25 |
+
.env
|
| 26 |
+
.venv
|
| 27 |
+
env/
|
| 28 |
+
venv/
|
| 29 |
+
ENV/
|
| 30 |
+
env.bak/
|
| 31 |
+
venv.bak/
|
| 32 |
+
|
| 33 |
+
# IDE
|
| 34 |
+
.vscode/
|
| 35 |
+
.idea/
|
| 36 |
+
*.swp
|
| 37 |
+
*.swo
|
| 38 |
+
*~
|
| 39 |
+
|
| 40 |
+
# OS
|
| 41 |
+
.DS_Store
|
| 42 |
+
.DS_Store?
|
| 43 |
+
._*
|
| 44 |
+
.Spotlight-V100
|
| 45 |
+
.Trashes
|
| 46 |
+
ehthumbs.db
|
| 47 |
+
Thumbs.db
|
| 48 |
+
|
| 49 |
+
# Gradio
|
| 50 |
+
gradio_cached_examples/
|
| 51 |
+
flagged/
|
| 52 |
+
|
| 53 |
+
# Hugging Face
|
| 54 |
+
.huggingface/
|
README.md
CHANGED
|
@@ -1,14 +1,55 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
-
short_description:
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: HF News (AI-assisted summary)
|
| 3 |
+
emoji: π°
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
+
short_description: Stay updated with AI/ML news, summarized by AI
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# π HF News (AI-assisted summary) π°
|
| 15 |
+
|
| 16 |
+
A playful Gradio application that displays the latest AI and ML news summaries from the [HF News Aggregator dataset](https://huggingface.co/datasets/rajatarya/hf-news-aggregator).
|
| 17 |
+
|
| 18 |
+
## β¨ Features
|
| 19 |
+
|
| 20 |
+
- π° **Latest News First**: Always shows the most recent AI-summarized news
|
| 21 |
+
- π§ **Easy Navigation**: Browse through older summaries with intuitive controls
|
| 22 |
+
- π **Rich Metadata**: View details about each summary including sources, time range, and analysis stats
|
| 23 |
+
- π¨ **Playful UI**: Emoji-rich interface with a modern, friendly design
|
| 24 |
+
- π **Live Updates**: Refresh button to get the latest data from the dataset
|
| 25 |
+
|
| 26 |
+
## π― How it Works
|
| 27 |
+
|
| 28 |
+
The application fetches data from the `rajatarya/hf-news-aggregator` dataset, which contains AI-generated summaries of news from various sources. Each summary includes:
|
| 29 |
+
|
| 30 |
+
- **Summarized Content**: AI-generated markdown summaries of the latest AI/ML news
|
| 31 |
+
- **Metadata**: Information about the summary generation process
|
| 32 |
+
- **Sources**: Details about the news sources analyzed
|
| 33 |
+
- **Time Range**: The period covered by each summary
|
| 34 |
+
|
| 35 |
+
## π Usage
|
| 36 |
+
|
| 37 |
+
Simply visit the Space and:
|
| 38 |
+
1. π View the latest news summary
|
| 39 |
+
2. β‘οΈ Navigate to newer summaries with the "Newer News" button
|
| 40 |
+
3. β¬
οΈ Browse older summaries with the "Older News" button
|
| 41 |
+
4. π Refresh to get the latest data from the dataset
|
| 42 |
+
|
| 43 |
+
## π οΈ Technical Details
|
| 44 |
+
|
| 45 |
+
Built with:
|
| 46 |
+
- **Gradio**: For the web interface
|
| 47 |
+
- **Pandas**: For data manipulation
|
| 48 |
+
- **Hugging Face Hub**: For dataset access
|
| 49 |
+
- **PyArrow**: For parquet file handling
|
| 50 |
+
|
| 51 |
+
The app automatically loads the latest parquet file from the dataset and presents it in a user-friendly format with proper markdown rendering.
|
| 52 |
+
|
| 53 |
+
---
|
| 54 |
+
|
| 55 |
+
*π€ Powered by AI β’ π Data from [HF News Aggregator](https://huggingface.co/datasets/rajatarya/hf-news-aggregator)*
|
app.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import json
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
def load_data():
|
| 9 |
+
"""Load the latest news data from the parquet file"""
|
| 10 |
+
try:
|
| 11 |
+
file_path = hf_hub_download(
|
| 12 |
+
repo_id='rajatarya/hf-news-aggregator',
|
| 13 |
+
filename='data/news_data_summaries.parquet',
|
| 14 |
+
repo_type='dataset'
|
| 15 |
+
)
|
| 16 |
+
df = pd.read_parquet(file_path)
|
| 17 |
+
# Sort by date_generated descending to get latest first
|
| 18 |
+
df = df.sort_values('date_generated', ascending=False).reset_index(drop=True)
|
| 19 |
+
return df
|
| 20 |
+
except Exception as e:
|
| 21 |
+
print(f"Error loading data: {e}")
|
| 22 |
+
return pd.DataFrame()
|
| 23 |
+
|
| 24 |
+
def format_metadata(metadata_str):
|
| 25 |
+
"""Format metadata as a readable string"""
|
| 26 |
+
try:
|
| 27 |
+
if isinstance(metadata_str, str):
|
| 28 |
+
metadata = json.loads(metadata_str)
|
| 29 |
+
else:
|
| 30 |
+
metadata = metadata_str
|
| 31 |
+
|
| 32 |
+
formatted = []
|
| 33 |
+
for key, value in metadata.items():
|
| 34 |
+
if key == 'generated_at':
|
| 35 |
+
# Format timestamp
|
| 36 |
+
try:
|
| 37 |
+
dt = datetime.fromisoformat(value.replace('Z', '+00:00'))
|
| 38 |
+
formatted.append(f"**Generated:** {dt.strftime('%Y-%m-%d %H:%M UTC')}")
|
| 39 |
+
except:
|
| 40 |
+
formatted.append(f"**Generated:** {value}")
|
| 41 |
+
else:
|
| 42 |
+
formatted.append(f"**{key.replace('_', ' ').title()}:** {value}")
|
| 43 |
+
|
| 44 |
+
return "<br>".join(formatted)
|
| 45 |
+
except:
|
| 46 |
+
return str(metadata_str)
|
| 47 |
+
|
| 48 |
+
def get_news_content(index):
|
| 49 |
+
"""Get news content for a specific index"""
|
| 50 |
+
df = load_data()
|
| 51 |
+
|
| 52 |
+
if df.empty or index >= len(df):
|
| 53 |
+
return (
|
| 54 |
+
"β No data available",
|
| 55 |
+
"",
|
| 56 |
+
f"0 / 0",
|
| 57 |
+
gr.update(interactive=False),
|
| 58 |
+
gr.update(interactive=False)
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
row = df.iloc[index]
|
| 62 |
+
|
| 63 |
+
# Format the main content
|
| 64 |
+
title = f"π° HF News Summary - {row['summary_type'].title()} ({row['provider']})"
|
| 65 |
+
|
| 66 |
+
# Create metadata table
|
| 67 |
+
metadata_html = f"""
|
| 68 |
+
<div style="background: #f8f9fa; padding: 15px; border-radius: 8px; margin: 10px 0;">
|
| 69 |
+
<h4>π Summary Details</h4>
|
| 70 |
+
<table style="width: 100%; font-size: 0.9em;">
|
| 71 |
+
<tr><td><strong>ποΈ Date Generated:</strong></td><td>{row['date_generated'].strftime('%Y-%m-%d %H:%M UTC')}</td></tr>
|
| 72 |
+
<tr><td><strong>β° Time Range:</strong></td><td>{row['time_range']}</td></tr>
|
| 73 |
+
<tr><td><strong>π Articles Analyzed:</strong></td><td>{row['num_articles_analyzed']}</td></tr>
|
| 74 |
+
<tr><td><strong>π Sources:</strong></td><td>{row['sources']}</td></tr>
|
| 75 |
+
<tr><td><strong>π€ Provider:</strong></td><td>{row['provider']}</td></tr>
|
| 76 |
+
</table>
|
| 77 |
+
<div style="margin-top: 10px;">
|
| 78 |
+
<strong>βοΈ Metadata:</strong><br>
|
| 79 |
+
{format_metadata(row['metadata'])}
|
| 80 |
+
</div>
|
| 81 |
+
</div>
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
# Navigation info
|
| 85 |
+
nav_info = f"{index + 1} / {len(df)}"
|
| 86 |
+
|
| 87 |
+
# Navigation buttons state
|
| 88 |
+
prev_disabled = index >= len(df) - 1
|
| 89 |
+
next_disabled = index <= 0
|
| 90 |
+
|
| 91 |
+
return (
|
| 92 |
+
title,
|
| 93 |
+
metadata_html + "\n\n" + row['summarized_markdown'],
|
| 94 |
+
nav_info,
|
| 95 |
+
gr.update(interactive=not prev_disabled),
|
| 96 |
+
gr.update(interactive=not next_disabled)
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
# Global state for current index
|
| 100 |
+
current_index = 0
|
| 101 |
+
|
| 102 |
+
def next_news():
|
| 103 |
+
global current_index
|
| 104 |
+
current_index = max(0, current_index - 1) # Newer news (lower index)
|
| 105 |
+
return get_news_content(current_index)
|
| 106 |
+
|
| 107 |
+
def prev_news():
|
| 108 |
+
global current_index
|
| 109 |
+
df = load_data()
|
| 110 |
+
current_index = min(len(df) - 1, current_index + 1) # Older news (higher index)
|
| 111 |
+
return get_news_content(current_index)
|
| 112 |
+
|
| 113 |
+
def refresh_data():
|
| 114 |
+
global current_index
|
| 115 |
+
current_index = 0 # Reset to latest
|
| 116 |
+
return get_news_content(current_index)
|
| 117 |
+
|
| 118 |
+
# Create the Gradio interface
|
| 119 |
+
with gr.Blocks(
|
| 120 |
+
title="HF News (AI-assisted summary)",
|
| 121 |
+
theme=gr.themes.Soft(),
|
| 122 |
+
css="""
|
| 123 |
+
.news-container {
|
| 124 |
+
max-width: 1200px;
|
| 125 |
+
margin: 0 auto;
|
| 126 |
+
}
|
| 127 |
+
.nav-button {
|
| 128 |
+
font-size: 16px !important;
|
| 129 |
+
padding: 10px 20px !important;
|
| 130 |
+
}
|
| 131 |
+
"""
|
| 132 |
+
) as app:
|
| 133 |
+
gr.HTML("""
|
| 134 |
+
<div style="text-align: center; padding: 20px;">
|
| 135 |
+
<h1>π HF News (AI-assisted summary) π°</h1>
|
| 136 |
+
<p style="font-size: 18px; color: #666;">
|
| 137 |
+
Stay updated with the latest AI and ML news, summarized by AI! β¨
|
| 138 |
+
</p>
|
| 139 |
+
</div>
|
| 140 |
+
""")
|
| 141 |
+
|
| 142 |
+
with gr.Row():
|
| 143 |
+
with gr.Column(scale=1):
|
| 144 |
+
refresh_btn = gr.Button("π Refresh Data", variant="secondary")
|
| 145 |
+
with gr.Column(scale=2):
|
| 146 |
+
nav_info = gr.Textbox(
|
| 147 |
+
label="π Position",
|
| 148 |
+
interactive=False,
|
| 149 |
+
container=False
|
| 150 |
+
)
|
| 151 |
+
with gr.Column(scale=1):
|
| 152 |
+
pass # Empty column for spacing
|
| 153 |
+
|
| 154 |
+
title_display = gr.Textbox(
|
| 155 |
+
label="π Current Summary",
|
| 156 |
+
interactive=False,
|
| 157 |
+
container=False
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
content_display = gr.Markdown(
|
| 161 |
+
label="π Content",
|
| 162 |
+
value="Loading news data... π"
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
with gr.Row():
|
| 166 |
+
prev_btn = gr.Button("β¬
οΈ Older News", variant="secondary", elem_classes="nav-button")
|
| 167 |
+
next_btn = gr.Button("β‘οΈ Newer News", variant="primary", elem_classes="nav-button")
|
| 168 |
+
|
| 169 |
+
gr.HTML("""
|
| 170 |
+
<div style="text-align: center; padding: 20px; color: #666; font-size: 14px;">
|
| 171 |
+
<p>π€ Powered by AI β’ π Data from <a href="https://huggingface.co/datasets/rajatarya/hf-news-aggregator" target="_blank">HF News Aggregator</a></p>
|
| 172 |
+
</div>
|
| 173 |
+
""")
|
| 174 |
+
|
| 175 |
+
# Event handlers
|
| 176 |
+
app.load(
|
| 177 |
+
fn=lambda: get_news_content(0),
|
| 178 |
+
outputs=[title_display, content_display, nav_info, prev_btn, next_btn]
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
next_btn.click(
|
| 182 |
+
fn=next_news,
|
| 183 |
+
outputs=[title_display, content_display, nav_info, prev_btn, next_btn]
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
prev_btn.click(
|
| 187 |
+
fn=prev_news,
|
| 188 |
+
outputs=[title_display, content_display, nav_info, prev_btn, next_btn]
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
refresh_btn.click(
|
| 192 |
+
fn=refresh_data,
|
| 193 |
+
outputs=[title_display, content_display, nav_info, prev_btn, next_btn]
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
if __name__ == "__main__":
|
| 197 |
+
app.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|
| 2 |
+
pandas>=1.5.0
|
| 3 |
+
huggingface_hub>=0.16.0
|
| 4 |
+
pyarrow>=10.0.0
|