fd / index.html
Kamocodes's picture
Got it 👍 — you want to **integrate the Gradio Stable Diffusion API** for generating images, combine it with your **news UI + serverless backend**, and make sure the site supports **article navigation + responsive design**. Here’s how we can plug it all together: --- ## ✅ Updated Full Stack Setup ### 1. **Image API Service (StabilityAI via Gradio)** We’ll create a small wrapper function in `services/imageService.js`: ```js // services/imageService.js import { Client } from "@gradio/client"; let client; export async function initClient() { if (!client) { client = await Client.connect("stabilityai/stable-diffusion"); } return client; } export async function generateImage(prompt, negative = "") { try { const client = await initClient(); const result = await client.predict("/infer", { prompt, negative, scale: 7.5, // typical scale for better results }); return result.data[0]; // return first generated image URL/base64 } catch (err) { console.error("Image generation failed:", err); return null; } } ``` --- ### 2. **Serverless Backend (Netlify Functions / Vercel API Routes)** Example for Vercel (`/api/generate-image.js`): ```js // api/generate-image.js import { generateImage } from "../services/imageService.js"; export default async function handler(req, res) { if (req.method !== "POST") { return res.status(405).json({ error: "Method not allowed" }); } const { prompt } = req.body; if (!prompt) { return res.status(400).json({ error: "Prompt required" }); } const image = await generateImage(prompt); if (!image) { return res.status(500).json({ error: "Image generation failed" }); } res.status(200).json({ image }); } ``` --- ### 3. **UI Integration (React Frontend)** In `ArticleCard.jsx` (where each news story is displayed): ```jsx import { useState } from "react"; export default function ArticleCard({ article }) { const [image, setImage] = useState(article.urlToImage); async function fetchAiImage() { try { const res = await fetch("/api/generate-image", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ prompt: article.title }), }); const data = await res.json(); if (data.image) setImage(data.image); } catch (err) { console.error("AI Image fetch failed", err); } } return ( <div className="bg-white dark:bg-gray-900 rounded-2xl shadow-md p-4 flex flex-col"> <img src={image} alt={article.title} className="rounded-xl object-cover h-48 w-full" /> <h2 className="text-lg font-bold mt-3">{article.title}</h2> <p className="text-sm text-gray-600 dark:text-gray-300"> {article.description} </p> <div className="flex justify-between mt-3"> <a href={`/article/${encodeURIComponent(article.title)}`} className="text-blue-600 hover:underline" > Read More → </a> <button onClick={fetchAiImage} className="text-xs bg-blue-500 text-white px-3 py-1 rounded-lg" > Generate AI Image </button> </div> </div> ); } ``` --- ### 4. **Responsive Navigation** Use Tailwind + responsive grid: ```jsx <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 p-6"> {articles.map((a, i) => ( <ArticleCard key={i} article={a} /> ))} </div> ``` --- ### 5. **Article Page Routing** If using **Next.js**: * `/pages/article/[slug].jsx` → loads full content. If using **React Router**: * `App.jsx`: ```jsx <Routes> <Route path="/" element={<HomePage />} /> <Route path="/article/:slug" element={<ArticlePage />} /> </Routes> ``` --- 🚀 This setup gives you: * **News UI** (grid + responsive cards) * **Navigation** to full article pages * **AI-powered images** per article via Stable Diffusion API * **Serverless backend** for clean API calls --- Do you want me to **make the `ArticlePage.jsx` (full article view)** right now so the navigation works end-to-end? - Initial Deployment
33986a6 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modern News Website</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Poppins', sans-serif;
}
.article-card {
transition: all 0.3s ease;
border-radius: 16px;
}
.article-card:hover {
transform: scale(1.02);
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
.category-badge {
position: absolute;
top: 15px;
left: 15px;
z-index: 10;
}
.search-btn {
transition: all 0.3s ease;
}
.search-btn:hover {
transform: scale(1.05);
}
.hamburger {
display: none;
}
@media (max-width: 768px) {
.hamburger {
display: block;
}
.nav-links {
display: none;
}
.nav-links.active {
display: flex;
flex-direction: column;
position: absolute;
top: 70px;
left: 0;
width: 100%;
background-color: white;
padding: 20px;
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
z-index: 50;
}
.search-container {
flex-direction: column;
}
.search-container input,
.search-container button {
width: 100%;
border-radius: 16px !important;
}
.search-container input {
margin-bottom: 10px;
}
}
</style>
</head>
<body class="bg-white">
<!-- Header/Navigation -->
<header class="bg-white shadow-sm sticky top-0 z-40">
<div class="container mx-auto px-4 py-4 flex justify-between items-center">
<div class="flex items-center">
<h1 class="text-2xl font-bold text-indigo-600">NewsHub</h1>
</div>
<div class="nav-links hidden md:flex space-x-8">
<a href="#" class="text-gray-700 hover:text-indigo-600 font-medium">Home</a>
<a href="#" class="text-gray-700 hover:text-indigo-600 font-medium">Categories</a>
<a href="#" class="text-gray-700 hover:text-indigo-600 font-medium">Trending</a>
<a href="#" class="text-gray-700 hover:text-indigo-600 font-medium">About</a>
<a href="#" class="text-gray-700 hover:text-indigo-600 font-medium">Contact</a>
</div>
<button class="hamburger md:hidden text-gray-700">
<i class="fas fa-bars text-2xl"></i>
</button>
</div>
</header>
<!-- Hero Section -->
<section class="py-16 md:py-24 bg-white">
<div class="container mx-auto px-4 text-center">
<span class="text-sm uppercase tracking-wider text-gray-500 font-semibold">Latest Articles</span>
<h1 class="text-4xl md:text-5xl font-bold text-gray-800 mt-4 mb-6">Discover our latest news</h1>
<p class="text-lg text-gray-600 max-w-2xl mx-auto mb-10">
Discover the achievements that set us apart. From groundbreaking projects to industry accolades, we take pride in our accomplishments.
</p>
<div class="max-w-2xl mx-auto flex search-container">
<input type="text" placeholder="Input Placeholder" class="flex-grow px-6 py-3 rounded-l-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
<button class="search-btn bg-indigo-600 text-white px-6 py-3 rounded-r-lg font-medium hover:bg-indigo-700 transition-colors">
Find Now
</button>
</div>
</div>
</section>
<!-- Main Content -->
<main class="container mx-auto px-4 py-12">
<div class="flex flex-col md:flex-row gap-8">
<!-- Articles Grid -->
<div class="w-full">
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
<!-- Article Card 1 -->
<div class="article-card bg-white rounded-2xl shadow-md overflow-hidden hover:shadow-lg cursor-pointer">
<div class="relative">
<img src="https://source.unsplash.com/random/600x400/?technology" alt="Article thumbnail" class="w-full object-cover aspect-[4/5]">
<span class="category-badge bg-indigo-600 text-white text-xs font-semibold px-3 py-1 rounded-full">Technology</span>
</div>
<div class="p-5">
<h3 class="text-xl font-bold text-gray-800 mb-2 line-clamp-3">The Future of AI in Everyday Life</h3>
<p class="text-gray-600 text-sm mb-4 line-clamp-2">Exploring how artificial intelligence will transform our daily routines and work environments in the coming decade.</p>
<div class="flex items-center">
<div class="w-8 h-8 rounded-full bg-gray-300 overflow-hidden mr-3">
<img src="https://randomuser.me/api/portraits/women/44.jpg" alt="Author" class="w-full h-full object-cover">
</div>
<div>
<p class="text-sm font-medium text-gray-800">Sarah Johnson</p>
<p class="text-xs text-gray-500">July 20, 2024</p>
</div>
</div>
</div>
</div>
<!-- Article Card 2 -->
<div class="article-card bg-white rounded-2xl shadow-md overflow-hidden hover:shadow-lg cursor-pointer">
<div class="relative">
<img src="https://source.unsplash.com/random/600x400/?travel" alt="Article thumbnail" class="w-full object-cover aspect-[4/5]">
<span class="category-badge bg-green-500 text-white text-xs font-semibold px-3 py-1 rounded-full">Travel</span>
</div>
<div class="p-5">
<h3 class="text-xl font-bold text-gray-800 mb-2 line-clamp-3">Hidden Gems in Southeast Asia</h3>
<p class="text-gray-600 text-sm mb-4 line-clamp-2">Discover these 5 underrated destinations that offer authentic experiences away from tourist crowds.</p>
<div class="flex items-center">
<div class="w-8 h-8 rounded-full bg-gray-300 overflow-hidden mr-3">
<img src="https://randomuser.me/api/portraits/men/32.jpg" alt="Author" class="w-full h-full object-cover">
</div>
<div>
<p class="text-sm font-medium text-gray-800">Michael Chen</p>
<p class="text-xs text-gray-500">July 18, 2024</p>
</div>
</div>
</div>
</div>
<!-- Article Card 3 -->
<div class="article-card bg-white rounded-2xl shadow-md overflow-hidden hover:shadow-lg cursor-pointer">
<div class="relative">
<img src="https://source.unsplash.com/random/600x400/?health" alt="Article thumbnail" class="w-full object-cover aspect-[4/5]">
<span class="category-badge bg-blue-500 text-white text-xs font-semibold px-3 py-1 rounded-full">Health</span>
</div>
<div class="p-5">
<h3 class="text-xl font-bold text-gray-800 mb-2 line-clamp-3">The Science of Better Sleep</h3>
<p class="text-gray-600 text-sm mb-4 line-clamp-2">New research reveals surprising techniques to improve sleep quality and overall health based on circadian rhythms.</p>
<div class="flex items-center">
<div class="w-8 h-8 rounded-full bg-gray-300 overflow-hidden mr-3">
<img src="https://randomuser.me/api/portraits/women/68.jpg" alt="Author" class="w-full h-full object-cover">
</div>
<div>
<p class="text-sm font-medium text-gray-800">Dr. Emily Parker</p>
<p class="text-xs text-gray-500">July 15, 2024</p>
</div>
</div>
</div>
</div>
<!-- Article Card 4 -->
<div class="article-card bg-white rounded-2xl shadow-md overflow-hidden hover:shadow-lg cursor-pointer">
<div class="relative">
<img src="https://source.unsplash.com/random/600x400/?business" alt="Article thumbnail" class="w-full object-cover aspect-[4/5]">
<span class="category-badge bg-purple-500 text-white text-xs font-semibold px-3 py-1 rounded-full">Business</span>
</div>
<div class="p-5">
<h3 class="text-xl font-bold text-gray-800 mb-2 line-clamp-3">Remote Work Trends in 2024</h3>
<p class="text-gray-600 text-sm mb-4 line-clamp-2">How companies are adapting their policies and what employees really want from hybrid work arrangements.</p>
<div class="flex items-center">
<div class="w-8 h-8 rounded-full bg-gray-300 overflow-hidden mr-3">
<img src="https://randomuser.me/api/portraits/men/75.jpg" alt="Author" class="w-full h-full object-cover">
</div>
<div>
<p class="text-sm font-medium text-gray-800">David Wilson</p>
<p class="text-xs text-gray-500">July 12, 2024</p>
</div>
</div>
</div>
</div>
<!-- Article Card 5 -->
<div class="article-card bg-white rounded-2xl shadow-md overflow-hidden hover:shadow-lg cursor-pointer">
<div class="relative">
<img src="https://source.unsplash.com/random/600x400/?food" alt="Article thumbnail" class="w-full object-cover aspect-[4/5]">
<span class="category-badge bg-red-500 text-white text-xs font-semibold px-3 py-1 rounded-full">Food</span>
</div>
<div class="p-5">
<h3 class="text-xl font-bold text-gray-800 mb-2 line-clamp-3">Plant-Based Diets: Beyond the Hype</h3>
<p class="text-gray-600 text-sm mb-4 line-clamp-2">Nutritionists weigh in on the long-term benefits and potential pitfalls of modern plant-based eating trends.</p>
<div class="flex items-center">
<div class="w-8 h-8 rounded-full bg-gray-300 overflow-hidden mr-3">
<img src="https://randomuser.me/api/portraits/women/33.jpg" alt="Author" class="w-full h-full object-cover">
</div>
<div>
<p class="text-sm font-medium text-gray-800">Lisa Rodriguez</p>
<p class="text-xs text-gray-500">July 10, 2024</p>
</div>
</div>
</div>
</div>
<!-- Article Card 6 -->
<div class="article-card bg-white rounded-2xl shadow-md overflow-hidden hover:shadow-lg cursor-pointer">
<div class="relative">
<img src="https://source.unsplash.com/random/600x400/?sports" alt="Article thumbnail" class="w-full object-cover aspect-[4/5]">
<span class="category-badge bg-orange-500 text-white text-xs font-semibold px-3 py-1 rounded-full">Sports</span>
</div>
<div class="p-5">
<h3 class="text-xl font-bold text-gray-800 mb-2 line-clamp-3">The Rise of Women's Sports Viewership</h3>
<p class="text-gray-600 text-sm mb-4 line-clamp-2">Record-breaking attendance and TV ratings signal a cultural shift in sports entertainment and sponsorship.</p>
<div class="flex items-center">
<div class="w-8 h-8 rounded-full bg-gray-300 overflow-hidden mr-3">
<img src="https://randomuser.me/api/portraits/men/45.jpg" alt="Author" class="w-full h-full object-cover">
</div>
<div>
<p class="text-sm font-medium text-gray-800">James Peterson</p>
<p class="text-xs text-gray-500">July 8, 2024</p>
</div>
</div>
</div>
</div>
</div>
<!-- Pagination -->
<div class="flex justify-center mt-12">
<nav class="flex items-center space-x-2">
<button class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">
<i class="fas fa-chevron-left"></i>
</button>
<button class="px-4 py-2 bg-indigo-600 text-white rounded-md font-medium">1</button>
<button class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">2</button>
<button class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">3</button>
<span class="px-2 text-gray-500">...</span>
<button class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">8</button>
<button class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">
<i class="fas fa-chevron-right"></i>
</button>
</nav>
</div>
</div>
<!-- Sidebar -->
<div class="w-full md:w-1/4 space-y-8">
<!-- Categories -->
<div class="bg-white p-6 rounded-xl shadow-sm">
<h3 class="text-lg font-bold text-gray-800 mb-4">Categories</h3>
<ul class="space-y-3">
<li>
<a href="#" class="flex items-center justify-between text-gray-700 hover:text-indigo-600">
<span>Technology</span>
<span class="bg-gray-100 text-gray-600 text-xs px-2 py-1 rounded-full">24</span>
</a>
</li>
<li>
<a href="#" class="flex items-center justify-between text-gray-700 hover:text-indigo-600">
<span>Business</span>
<span class="bg-gray-100 text-gray-600 text-xs px-2 py-1 rounded-full">18</span>
</a>
</li>
<li>
<a href="#" class="flex items-center justify-between text-gray-700 hover:text-indigo-600">
<span>Health</span>
<span class="bg-gray-100 text-gray-600 text-xs px-2 py-1 rounded-full">15</span>
</a>
</li>
<li>
<a href="#" class="flex items-center justify-between text-gray-700 hover:text-indigo-600">
<span>Travel</span>
<span class="bg-gray-100 text-gray-600 text-xs px-2 py-1 rounded-full">12</span>
</a>
</li>
<li>
<a href="#" class="flex items-center justify-between text-gray-700 hover:text-indigo-600">
<span>Food</span>
<span class="bg-gray-100 text-gray-600 text-xs px-2 py-1 rounded-full">9</span>
</a>
</li>
<li>
<a href="#" class="flex items-center justify-between text-gray-700 hover:text-indigo-600">
<span>Sports</span>
<span class="bg-gray-100 text-gray-600 text-xs px-2 py-1 rounded-full">7</span>
</a>
</li>
</ul>
</div>
<!-- Popular Articles -->
<div class="bg-white p-6 rounded-xl shadow-sm">
<h3 class="text-lg font-bold text-gray-800 mb-4">Popular Articles</h3>
<ul class="space-y-4">
<li>
<a href="#" class="flex items-start space-x-3 group">
<div class="flex-shrink-0 w-16 h-16 rounded-md overflow-hidden">
<img src="https://source.unsplash.com/random/100x100/?tech" alt="Popular article" class="w-full h-full object-cover">
</div>
<div>
<h4 class="text-sm font-medium text-gray-800 group-hover:text-indigo-600">How Blockchain is Changing Finance</h4>
<p class="text-xs text-gray-500 mt-1">June 28, 2024</p>
</div>
</a>
</li>
<li>
<a href="#" class="flex items-start space-x-3 group">
<div class="flex-shrink-0 w-16 h-16 rounded-md overflow-hidden">
<img src="https://source.unsplash.com/random/100x100/?travel" alt="Popular article" class="w-full h-full object-cover">
</div>
<div>
<h4 class="text-sm font-medium text-gray-800 group-hover:text-indigo-600">Best Travel Destinations for Solo Travelers</h4>
<p class="text-xs text-gray-500 mt-1">June 25, 2024</p>
</div>
</a>
</li>
<li>
<a href="#" class="flex items-start space-x-3 group">
<div class="flex-shrink-0 w-16 h-16 rounded-md overflow-hidden">
<img src="https://source.unsplash.com/random/100x100/?health" alt="Popular article" class="w-full h-full object-cover">
</div>
<div>
<h4 class="text-sm font-medium text-gray-800 group-hover:text-indigo-600">Mental Health Tips for Remote Workers</h4>
<p class="text-xs text-gray-500 mt-1">June 22, 2024</p>
</div>
</a>
</li>
</ul>
</div>
<!-- Newsletter -->
<div class="bg-indigo-50 p-6 rounded-xl">
<h3 class="text-lg font-bold text-gray-800 mb-3">Subscribe to Newsletter</h3>
<p class="text-sm text-gray-600 mb-4">Get the latest articles and news delivered to your inbox.</p>
<form class="space-y-3">
<input type="email" placeholder="Your email address" class="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
<button type="submit" class="w-full bg-indigo-600 text-white py-2 rounded-md font-medium hover:bg-indigo-700 transition-colors">Subscribe</button>
</form>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="bg-gray-800 text-white py-12">
<div class="container mx-auto px-4">
<div class="grid grid-cols-1 md:grid-cols-4 gap-8">
<div>
<h3 class="text-xl font-bold mb-4">NewsHub</h3>
<p class="text-gray-400">Delivering quality news and insights to keep you informed and inspired.</p>
<div class="flex space-x-4 mt-6">
<a href="#" class="text-gray-400 hover:text-white"><i class="fab fa-twitter"></i></a>
<a href="#" class="text-gray-400 hover:text-white"><i class="fab fa-facebook"></i></a>
<a href="#" class="text-gray-400 hover:text-white"><i class="fab fa-instagram"></i></a>
<a href="#" class="text-gray-400 hover:text-white"><i class="fab fa-linkedin"></i></a>
</div>
</div>
<div>
<h4 class="font-bold text-lg mb-4">Quick Links</h4>
<ul class="space-y-2">
<li><a href="#" class="text-gray-400 hover:text-white">Home</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">About Us</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Categories</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Trending</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Contact</a></li>
</ul>
</div>
<div>
<h4 class="font-bold text-lg mb-4">Categories</h4>
<ul class="space-y-2">
<li><a href="#" class="text-gray-400 hover:text-white">Technology</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Business</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Health</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Travel</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Sports</a></li>
</ul>
</div>
<div>
<h4 class="font-bold text-lg mb-4">Contact Us</h4>
<address class="text-gray-400 not-italic">
<p class="mb-2">123 News Street, Media City</p>
<p class="mb-2">Email: info@newshub.com</p>
<p>Phone: (123) 456-7890</p>
</address>
</div>
</div>
<div class="border-t border-gray-700 mt-12 pt-8 text-center text-gray-400">
<p>&copy; 2024 NewsHub. All rights reserved.</p>
</div>
</div>
</footer>
<script>
// Mobile menu toggle
document.querySelector('.hamburger').addEventListener('click', function() {
document.querySelector('.nav-links').classList.toggle('active');
});
// Article card click handler
document.querySelectorAll('.article-card').forEach(card => {
card.addEventListener('click', function() {
// In a real app, this would navigate to the article page
alert('Navigating to article page...');
});
});
// Search functionality
document.querySelector('.search-btn').addEventListener('click', function() {
const searchTerm = document.querySelector('input[type="text"]').value;
if(searchTerm.trim() !== '') {
alert(`Searching for: ${searchTerm}`);
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Kamocodes/fd" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>