--- title: Chatbot Final emoji: ๐Ÿฆ€ colorFrom: red colorTo: yellow sdk: docker app_port: 8501 pinned: false license: mit --- --- # ๐Ÿค– Chatbot with Voice + Text | React + FastAPI + Ollama This is a full-stack chatbot application supporting both **text** and **voice input**, powered by: * **๐Ÿง  Ollama (LLM)** โ€” for chatbot responses using `krishna_choudhary/tinyllama` * **๐Ÿ—ฃ๏ธ Ollama (Whisper STT)** โ€” for voice-to-text transcription using `anagram/whispertiny` * **โš›๏ธ React** โ€” for a modern, responsive chat interface * **โšก FastAPI** โ€” for backend API endpoints --- ## ๐Ÿ“‚ Fine-Tuning Dataset & Training Code ๐Ÿ‘‰ **Looking to fine-tune the chatbot yourself?** Check out the open-source dataset and training scripts used to fine-tune `tinyllama`: ๐Ÿ”— **GitHub Repository:** [Byte-Maste/krishna\_Chatbot\_Dataset](https://github.com/Byte-Maste/krishna_Chatbot_Dataset) This repository includes: * ๐Ÿ—ƒ๏ธ Custom chatbot dialogue dataset * ๐Ÿงช Fine-tuning scripts and setup * ๐Ÿ“Š Prompt formatting for LLM compatibility --- ## ๐Ÿš€ Features * ๐Ÿ’ฌ **Interactive Chat UI** โ€“ Clean and responsive frontend built in React * ๐ŸŽค **Voice Input (STT)** โ€“ Record your voice and transcribe using Whisper * ๐Ÿง  **Ollama LLM** โ€“ Generate AI responses locally using TinyLlama (or your preferred model) * ๐Ÿ” **Streaming Responses** โ€“ Responses are streamed back for a natural chat flow * ๐Ÿณ **Dockerized** โ€“ Easy deployment using Docker * ๐Ÿ›  **Modular Architecture** โ€“ Clean separation of concerns (React frontend, FastAPI backend) --- ## ๐Ÿงฉ Tech Stack | Layer | Tech | | -------- | -------------------------------------- | | Frontend | React (Vite) | | Backend | FastAPI | | LLM | Ollama - `krishna_choudhary/tinyllama` | | STT | Ollama - `anagram/whispertiny` | | Audio | Web Audio API | | Infra | Docker + Nginx (Production) | --- ## ๐Ÿ—‚๏ธ Project Structure ``` . โ”œโ”€โ”€ Dockerfile # Full app container (React + FastAPI + Ollama) โ”œโ”€โ”€ start.sh # Start script: launches Ollama & FastAPI โ”œโ”€โ”€ main.py # FastAPI server logic (LLM + STT endpoints) โ”œโ”€โ”€ requirements.txt # Python dependencies โ”œโ”€โ”€ nginx.conf # Nginx config for proxying & serving frontend โ””โ”€โ”€ frontend/ โ”œโ”€โ”€ src/App.jsx # React component with chat logic โ”œโ”€โ”€ src/App.css # App styles โ”œโ”€โ”€ dist/ # Production build output (after npm build) ``` --- ## ๐Ÿ› ๏ธ Local Development (No Docker) ### 1. Clone Repo ```bash git clone cd ``` ### 2. Backend Setup (FastAPI) ```bash pip install -r requirements.txt ``` ### 3. Frontend Setup (React) ```bash cd frontend npm install npm run build cd .. ``` ### 4. Start Ollama Locally ```bash ollama pull krishna_choudhary/tinyllama ollama pull anagram/whispertiny ollama serve ``` ### 5. Run FastAPI Server ```bash uvicorn main:app --host 0.0.0.0 --port 7860 ``` Then access via `http://localhost:7860` --- ## ๐Ÿณ Docker Deployment (Recommended) ### 1. Build Docker Image ```bash docker build -t chatbot-ollama-app . ``` ### 2. Run Container ```bash docker run -p 8501:8501 \ -e OLLAMA_HOST="http://127.0.0.1:11434" \ -e MODEL_NAME="krishna_choudhary/tinyllama" \ -e WHISPER_MODEL_NAME="anagram/whispertiny" \ chatbot-ollama-app ``` ### 3. Access App Open your browser at: ๐Ÿ‘‰ `http://localhost:8501` --- ## ๐ŸŽ™๏ธ Using the Chatbot * ๐Ÿง‘โ€๐Ÿ’ป **Text Input**: Type a question and hit **Send**. * ๐Ÿ—ฃ๏ธ **Voice Input**: Click the mic icon, speak, then click again to transcribe and submit. --- ## ๐Ÿ”ง Customization Options | What | How to Customize | | ------------- | -------------------------------------------------------- | | LLM Model | Change `MODEL_NAME` in `main.py` or `start.sh` | | Whisper Model | Update `WHISPER_MODEL_NAME` in `main.py` or `start.sh` | | Ollama Host | Modify `OLLAMA_HOST_URL` in `main.py` | | Token Speed | Adjust `asyncio.sleep()` delay inside streaming function | --- ## ๐Ÿงช Quick Test Without Nginx In development, React can directly call backend: * Set API base in frontend to `http://localhost:7860/api/` * Run React in dev mode: ```bash cd frontend npm run dev ``` --- ## ๐Ÿค License & Credits * Built with โค๏ธ using [FastAPI](https://fastapi.tiangolo.com/), [React](https://reactjs.org/), and [Ollama](https://ollama.com/) * Models: * `krishna_choudhary/tinyllama` * `anagram/whispertiny` * Dataset & Fine-tuning: * ๐Ÿ“ [Byte-Maste/krishna\_Chatbot\_Dataset](https://github.com/Byte-Maste/krishna_Chatbot_Dataset) ---