A lightning-fast, conversational AI agent that generates highly detailed images. The app uses Groq to intelligently understand your request and enhance your prompt, and Hugging Face (FLUX.1-schnell) to generate stunning, photorealistic images instantly.
- Demo Video: Watch on Loom
| Beautiful Scenery | A Porsche | A Futuristic Bugatti |
|---|---|---|
![]() |
![]() |
![]() |
- 🗣️ Conversational AI: Chat naturally with the Llama 3.3 model via Groq's blazing-fast inference.
- 🪄 Auto-Prompt Enhancement: When you ask for an image, Groq acts as a prompt engineer and automatically enhances your idea into a highly descriptive, visually stunning prompt.
- 🎨 High-Quality Image Generation: Uses the state-of-the-art FLUX.1-schnell model via Hugging Face to generate the actual image.
- ⚡ Synchronous Background Threads: Bypasses common Windows
asyncionetworking bugs usingasyncio.to_threadfor rock-solid stability. - 🗂️ Clean UI Workflow: Utilizes Chainlit's expandable Steps UI to clearly show the prompt enhancement process.
| Technology | Category | Purpose |
|---|---|---|
| Chainlit | Frontend / App Framework | Chat UI, state management, and conversational interface. |
| Groq (Llama 3.3 70B) | LLM / Text Generation | Conversational engine and prompt enhancement via function calling. |
| Hugging Face API | Model Inference | Serves the black-forest-labs/FLUX.1-schnell image generation model. |
| huggingface_hub | SDK | Official Python SDK to cleanly route HF inference API calls. |
- User Request: The user types a message or asks for an image in the Chainlit UI.
- Groq Analysis: The message is sent to Groq. If the user wants an image, Groq triggers the
generate_imagefunction call and rewrites the prompt to make it incredibly detailed. - Chainlit Step: The UI displays an expandable "Enhancing prompt & generating image..." step so the user can see the enhanced prompt.
- Hugging Face Generation: A background thread connects to the Hugging Face
InferenceClientto generate the image using FLUX.1. - Final Output: The generated bytes are converted to a
cl.Imageand displayed in the chat alongside a concluding message from Groq.
sequenceDiagram
participant User
participant Chainlit App
participant Groq (Llama 3.3)
participant Hugging Face (FLUX.1)
User->>Chainlit App: "Generate a monkey in a forest"
Chainlit App->>Groq (Llama 3.3): Forward chat history & tools
Groq (Llama 3.3)-->>Chainlit App: Tool Call (generate_image) + Enhanced Prompt
Chainlit App->>Chainlit App: Display "Enhancing prompt..." Step
Chainlit App->>Hugging Face (FLUX.1): Request Image Generation
Hugging Face (FLUX.1)-->>Chainlit App: Returns Image Bytes
Chainlit App->>User: Display Image
📦 Image-Generator-Chainlit-App
┣ 📂 .chainlit # Chainlit configuration files
┣ 📂 venv # Python virtual environment (ignored in git)
┣ 📜 app.py # Main application logic and routing
┣ 📜 chainlit.md # Welcome screen markdown
┣ 📜 .env # Environment variables (API Keys)
┗ 📜 requirements.txt # Python dependencies
1. Clone the repository
git clone https://github.com/Arslan-Codes097/Image-Generator-Chainlit-App-.git
cd Image-Generator-Chainlit-App-2. Create and activate a Virtual Environment
python -m venv venv
# On Windows:
.\venv\Scripts\activate
# On Mac/Linux:
source venv/bin/activate3. Install Dependencies
pip install -r requirements.txt4. Set up Environment Variables
Create a .env file in the root directory and add your API keys:
GROQ_API_KEY=your_groq_api_key_here
HF_API_KEY=your_huggingface_api_key_here5. Run the Application
chainlit run app.py -wDeveloped by @Arslan-Codes097
Built project using Chainlit, Groq, and Hugging Face.



