Skip to content

Instantly share code, notes, and snippets.

@anuragsolanki
Last active April 29, 2025 23:36
Show Gist options
  • Save anuragsolanki/efdfbaa1b9cfc5097b7c65b9ded4fd7a to your computer and use it in GitHub Desktop.
Save anuragsolanki/efdfbaa1b9cfc5097b7c65b9ded4fd7a to your computer and use it in GitHub Desktop.
Gist of Hackathon 2

πŸ“° News Summarizer Project β€” Full Build & Chat Transcript

πŸš€ Project Overview Backend: Ruby on Rails API (news_summarizer) Summarization Engine: Python script (HuggingFace Transformers + newspaper3k) Frontend: React app (news_summarizer_frontend) Goal: Paste a news article URL, get an AI-generated summary, with robust error handling, tests, and a modern, animated UI. πŸ‘€ User Requests & Actions

  1. πŸ› οΈ Initial Setup Build a Rails API endpoint to call a Python script for summarizing news articles. Ensure robust error handling and clear JSON responses.
  2. πŸ§ͺ Testing Add RSpec request specs for POST /summaries (both valid and invalid URLs).
  3. πŸ’» Frontend Scaffold a React app with: A single input for the article URL A "Summarize" button Loading, error, and summary display
  4. 🎨 UI/UX Enhancements Make the frontend attractive: centered, full-width input, modern spacing, and font sizes. Add a spinner animation while loading. Animate the summary box with a pop-in effect. Smoothly animate the white box size changes.
  5. πŸ”— Integration & Environment Enable CORS so React can POST to Rails. Fix NumPy 2.x incompatibility with PyTorch/transformers by downgrading to NumPy 1.x. Suppress all backend warnings and device prints (including β€œDevice set to use mps:0”). Ensure only clean summary text is returned to the frontend.
  6. πŸ“„ Transcript Export Requested a full export/gist of the chat and all input provided, both with and without code snippets.

πŸ› οΈ Key Decisions & Solutions

Error Handling: Rails controller captures Python errors and returns appropriate JSON with status codes.
Testing: RSpec request specs ensure both success and failure cases are covered.
CORS: Configured rack-cors to allow local frontend-backend development.
NumPy Fix: Downgraded NumPy to 1.26.4 to resolve compatibility issues.
Output Suppression: Used robust file-descriptor-level redirection to silence all backend prints during model loading.
Frontend UX: Added CSS transitions and animations for a smooth, modern user experience.
Loading Animation: Implemented a custom spinner for feedback during summary generation.
Summary Animation: Used CSS keyframes for a scaling/fade-in effect and smooth container resizing.
Transcript Export: Provided a full Markdown summary of the session, both with and without code.

πŸ“ Final Workflow

  1. User pastes a news article URL in the React frontend and clicks "Summarize."
  2. React sends a POST to the Rails backend.
  3. Rails controller invokes the Python script, which fetches and summarizes the article.
  4. All backend warnings and device prints are suppressed; only the summary is returned.
  5. React displays a spinner while loading and animates the summary when it appears.
  6. Errors are handled gracefully and shown to the user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment