π― 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 π‘