๐ฏ Goal: Help beginners build a simple, working AI app using React, Tailwind CSS, and a free AI API (like OpenAI or HuggingFace).
๐ง No heavy theory. No complex code. Just easy steps with real results.
๐ Why You Should Read This
- โ You're curious about AI but donโt know where to start
- โ You want a hands-on project to show off or use
- โ You like pretty UIs (Tailwind โค๏ธ)
- โ You want that โI built this myselfโ feeling!
๐งฐ What You'll Use
- React (with Vite for speed)
- Tailwind CSS for styling
- Free AI API (OpenAI or HuggingFace)
- Fetch API for making requests
๐ Letโs Get Started
๐จ Set Up Your Project
npm create vite@latest ai-react-app --template react cd ai-react-app npm install npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -p ๐ง Configure Tailwind
Replace the content of your tailwind.config.js with:
/** @type {import('tailwindcss').Config} */ export default { content: [ "./index.html", "./src/**/*.{js,ts,jsx,tsx}", ], theme: { extend: {}, }, plugins: [], } Update your src/index.css:
@tailwind base; @tailwind components; @tailwind utilities; And include it in your main.jsx:
import React from 'react' import ReactDOM from 'react-dom/client' import App from './App.jsx' import './index.css' ReactDOM.createRoot(document.getElementById('root')).render( <React.StrictMode> <App /> </React.StrictMode> ) ๐ง Create a Simple AI App
Letโs build a small text generator using OpenAI or HuggingFaceโs free API.
๐๏ธ Create Your App.jsx File :
import { useState } from "react"; function App() { const [input, setInput] = useState(""); const [response, setResponse] = useState(""); const [loading, setLoading] = useState(false); const handleGenerate = async () => { if (!input.trim()) return; setLoading(true); try { const res = await fetch("https://api-inference.huggingface.co/models/gpt2", { method: "POST", headers: { "Authorization": "Bearer YOUR_HUGGINGFACE_API_KEY", "Content-Type": "application/json" }, body: JSON.stringify({ inputs: input }) }); const data = await res.json(); setResponse(data?.[0]?.generated_text || "No response ๐ฅ"); } catch (err) { setResponse("Something went wrong ๐ต"); } finally { setLoading(false); } }; return ( <div className="min-h-screen bg-gray-900 text-white p-8 flex flex-col items-center justify-center"> <h1 className="text-3xl font-bold mb-6 text-center">๐ค Tiny AI Generator</h1> <textarea className="w-full max-w-md p-4 rounded bg-gray-800 mb-4" rows="5" placeholder="Type a sentence to continue..." value={input} onChange={(e) => setInput(e.target.value)} /> <button onClick={handleGenerate} className="bg-blue-500 hover:bg-blue-600 text-white px-6 py-2 rounded disabled:opacity-50" disabled={loading} > {loading ? "Generating..." : "Generate with AI"} </button> {response && ( <div className="mt-6 bg-gray-800 p-4 rounded max-w-md w-full"> <p className="text-green-400 font-semibold">AI Says:</p> <p>{response}</p> </div> )} </div> ); } export default App; ๐ Get Your API Key
1. Go to Hugging Face
2. Sign up or log in
3. Go to Settings โ Access Tokens โ Create a new token
4. Replace "YOUR_HUGGINGFACE_API_KEY" with your token
๐ Done! Youโve Built an AI App!
You just:
- ๐จ Set up a styled React app
- ๐ Connected to a real AI API
- โก Built an app that does something cool
Take a second and appreciate it โ youโre leveling up as a dev ๐ช
๐ก Bonus Ideas
Want to take it further?
- Let users choose tone or length
- Add history of responses
- Deploy it on Vercel or Netlify
- Use OpenAIโs GPT-3.5 API for better results
๐ฅ Final Thoughts
AI isnโt just for experts. Youโve already done more than most people just by building and experimenting.
Start small, stay curious, and keep shipping ๐
๐ Like This? Letโs Connect!
- ๐ Instagram: @tahamjp
- ๐ Check out more: My Other Dev Articles
๐ฌ Leave a comment below if you got stuck or want help!
๐งโ๐ป Written by Taha Majlesi
Top comments (1)
๐ Thanks for reading! Follow me for more front-end tips ๐ก