Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- DockerFile.txt +17 -0
- README.md +175 -0
- app.py +291 -0
- requirements.txt +26 -0
DockerFile.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a lightweight official Python image
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy project files
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
# Install dependencies
|
| 11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Expose Hugging Face’s default port
|
| 14 |
+
EXPOSE 7860
|
| 15 |
+
|
| 16 |
+
# Launch FastAPI
|
| 17 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: AI Mirror Backend
|
| 3 |
+
emoji: 🪞
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_file: app.py
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
## 💡 Project Overview
|
| 11 |
+
|
| 12 |
+
In today's digital world, people express thousands of thoughts through messages, tweets, and posts — but rarely pause to see what those words say about their *emotions*.
|
| 13 |
+
**AI Mirror** is an innovative **AI + GenAI-powered Data Analytics project** that transforms text into emotional insights, visualizes mood trends, and even generates AI-based art that represents how you *feel*.
|
| 14 |
+
|
| 15 |
+
It's not just analytics — it's **emotion intelligence visualized through data.**
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
## 🧠 Core Idea
|
| 20 |
+
|
| 21 |
+
AI Mirror reads and interprets your text, detects emotions using NLP models, and then creates:
|
| 22 |
+
|
| 23 |
+
* **Mood Analysis Graphs**
|
| 24 |
+
* **AI-generated summaries**
|
| 25 |
+
* **Emotion-based artwork**
|
| 26 |
+
* **Personalized mood reports**
|
| 27 |
+
|
| 28 |
+
It acts as your **digital emotional reflection**, powered by data science and creativity.
|
| 29 |
+
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
## 📊 Datasets Used
|
| 33 |
+
|
| 34 |
+
### 🧩 1. Emotion Dataset for NLP (Kaggle)
|
| 35 |
+
* Contains ~20,000 text samples labeled with 6 emotions: *joy, sadness, anger, fear, love, surprise.*
|
| 36 |
+
* Used for training and initial testing of the emotion classification model.
|
| 37 |
+
|
| 38 |
+
### 🔮 2. GoEmotions (Google / Hugging Face)
|
| 39 |
+
* Contains 58,000 Reddit comments labeled with 27 nuanced emotions.
|
| 40 |
+
* Used to enhance realism and deepen emotional understanding.
|
| 41 |
+
|
| 42 |
+
---
|
| 43 |
+
|
| 44 |
+
## 📈 Key Features
|
| 45 |
+
|
| 46 |
+
✨ **Emotion Analytics Dashboard** – Displays emotion intensity, trends, and sentiment graphs.
|
| 47 |
+
🧠 **AI Mood Summary** – ChatGPT/Gemini writes human-like emotional insights.
|
| 48 |
+
🎨 **Mood Landscape Generator** – AI creates stunning 4K nature landscapes with weather/seasons matching your emotions.
|
| 49 |
+
📘 **PDF Report Export** – Auto-generated "Weekly Mood Reflection Report."
|
| 50 |
+
💬 **Chatbot Mode** – "Ask your AI Mirror how you feel today."
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
## 🧰 Tech Stack
|
| 55 |
+
|
| 56 |
+
| Category | Tools & Frameworks |
|
| 57 |
+
| -------------------- | ------------------------------------------------------ |
|
| 58 |
+
| Data Handling | Pandas, NumPy |
|
| 59 |
+
| NLP & Modeling | Hugging Face Transformers (BERT, DistilBERT), TextBlob |
|
| 60 |
+
| Visualization | Plotly, Seaborn, Matplotlib |
|
| 61 |
+
| GenAI APIs | ChatGPT (OpenAI), Google Gemini |
|
| 62 |
+
| AI Image Generation | DALL·E / Stable Diffusion |
|
| 63 |
+
| Frontend | React, TailwindCSS, shadcn/ui |
|
| 64 |
+
| Backend | FastAPI, Python |
|
| 65 |
+
| Deployment | Netlify (Frontend) + Render (Backend) |
|
| 66 |
+
|
| 67 |
+
---
|
| 68 |
+
|
| 69 |
+
## 🚀 Getting Started
|
| 70 |
+
|
| 71 |
+
### Prerequisites
|
| 72 |
+
- Node.js 18+ and npm
|
| 73 |
+
- Python 3.9+
|
| 74 |
+
- API Keys: OpenAI, Google Gemini (optional)
|
| 75 |
+
|
| 76 |
+
### Backend Setup
|
| 77 |
+
|
| 78 |
+
```bash
|
| 79 |
+
cd backend
|
| 80 |
+
pip install -r requirements.txt
|
| 81 |
+
python download_models.py # Download NLP models
|
| 82 |
+
uvicorn main:app --reload
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
### Frontend Setup
|
| 86 |
+
|
| 87 |
+
```bash
|
| 88 |
+
cd frontend
|
| 89 |
+
npm install
|
| 90 |
+
npm run dev
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
---
|
| 94 |
+
|
| 95 |
+
## 📁 Project Structure
|
| 96 |
+
|
| 97 |
+
```
|
| 98 |
+
ai-mirror/
|
| 99 |
+
├── backend/
|
| 100 |
+
│ ├── main.py # FastAPI application
|
| 101 |
+
│ ├── emotion_detector.py # NLP emotion detection
|
| 102 |
+
│ ├── ai_insights.py # LLM integration
|
| 103 |
+
│ ├── art_generator.py # GenAI art creation
|
| 104 |
+
│ ├── visualizations.py # Data visualization
|
| 105 |
+
│ ├── pdf_generator.py # Report generation
|
| 106 |
+
│ └── requirements.txt
|
| 107 |
+
├── frontend/
|
| 108 |
+
│ ├── src/
|
| 109 |
+
│ │ ├── components/ # React components
|
| 110 |
+
│ │ ├── pages/ # Main pages
|
| 111 |
+
│ │ └── App.jsx
|
| 112 |
+
│ ├── package.json
|
| 113 |
+
│ └── vite.config.js
|
| 114 |
+
└── README.md
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
---
|
| 118 |
+
|
| 119 |
+
## 🌟 Expected Output
|
| 120 |
+
|
| 121 |
+
* Emotion frequency chart
|
| 122 |
+
* Sentiment timeline
|
| 123 |
+
* Word clouds of dominant emotions
|
| 124 |
+
* AI-generated mood artwork
|
| 125 |
+
* GPT-powered emotional summary
|
| 126 |
+
* Personalized downloadable report
|
| 127 |
+
|
| 128 |
+
Example:
|
| 129 |
+
|
| 130 |
+
> **Detected Emotions:** 60% calm, 25% joy, 15% tiredness
|
| 131 |
+
> **AI Summary:** "You seem emotionally balanced yet slightly fatigued — a calm achiever mood."
|
| 132 |
+
> **AI Artwork Title:** *'Serenity in Motion'*
|
| 133 |
+
|
| 134 |
+
---
|
| 135 |
+
|
| 136 |
+
## 🚀 Deployment
|
| 137 |
+
|
| 138 |
+
🌐 **Frontend:** React interface deployed on **Netlify**
|
| 139 |
+
🧩 **Backend:** FastAPI deployed on **Render**
|
| 140 |
+
🎨 **Model & Art Integration:**
|
| 141 |
+
* Hugging Face Transformers for emotion detection
|
| 142 |
+
* OpenAI/DALL·E API for art creation
|
| 143 |
+
* Gemini/ChatGPT for summaries
|
| 144 |
+
|
| 145 |
+
---
|
| 146 |
+
|
| 147 |
+
## 📘 Skills Showcased
|
| 148 |
+
|
| 149 |
+
✅ NLP & Text Analytics
|
| 150 |
+
✅ Data Cleaning & Feature Engineering
|
| 151 |
+
✅ Predictive Modeling (BERT)
|
| 152 |
+
✅ AI Summarization (LLMs)
|
| 153 |
+
✅ Visualization & Data Storytelling
|
| 154 |
+
✅ GenAI Integration (Image + Text Generation)
|
| 155 |
+
✅ Full-stack AI Deployment
|
| 156 |
+
|
| 157 |
+
---
|
| 158 |
+
|
| 159 |
+
## 👨💻 Developer
|
| 160 |
+
|
| 161 |
+
**Sayed Mohd Zayeem Khateeb**
|
| 162 |
+
📧 Email: [zayeem.s.khateeb@gmail.com](mailto:zayeem.s.khateeb@gmail.com)
|
| 163 |
+
💼 LinkedIn: [linkedin.com/in/zayeemkhateeb](https://www.linkedin.com/in/zayeemkhateeb)
|
| 164 |
+
|
| 165 |
+
---
|
| 166 |
+
|
| 167 |
+
## 💫 Tagline
|
| 168 |
+
|
| 169 |
+
> **"AI Mirror doesn't just read your words — it reflects your emotions."**
|
| 170 |
+
|
| 171 |
+
---
|
| 172 |
+
|
| 173 |
+
## 📄 Usage
|
| 174 |
+
|
| 175 |
+
This project is available for learning and portfolio purposes.
|
app.py
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, UploadFile, File
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from fastapi.responses import FileResponse, JSONResponse
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
from typing import List, Optional
|
| 6 |
+
import os
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
import logging
|
| 9 |
+
|
| 10 |
+
from emotion_detector import EmotionDetector
|
| 11 |
+
from ai_insights import AIInsightGenerator
|
| 12 |
+
from art_generator import MoodArtGenerator
|
| 13 |
+
from visualizations import VisualizationGenerator
|
| 14 |
+
from pdf_generator import PDFReportGenerator
|
| 15 |
+
|
| 16 |
+
# Load environment variables
|
| 17 |
+
load_dotenv()
|
| 18 |
+
|
| 19 |
+
# Configure logging
|
| 20 |
+
logging.basicConfig(level=logging.INFO)
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
# Initialize FastAPI app
|
| 24 |
+
app = FastAPI(
|
| 25 |
+
title="AI Mirror API",
|
| 26 |
+
description="The Data-Driven Mood & Personality Visualizer",
|
| 27 |
+
version="1.0.0"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Configure CORS
|
| 31 |
+
origins = os.getenv("ALLOWED_ORIGINS", "http://localhost:5173").split(",")
|
| 32 |
+
app.add_middleware(
|
| 33 |
+
CORSMiddleware,
|
| 34 |
+
allow_origins=origins,
|
| 35 |
+
allow_credentials=True,
|
| 36 |
+
allow_methods=["*"],
|
| 37 |
+
allow_headers=["*"],
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Initialize components
|
| 41 |
+
emotion_detector = EmotionDetector()
|
| 42 |
+
ai_insights = AIInsightGenerator()
|
| 43 |
+
art_generator = MoodArtGenerator()
|
| 44 |
+
viz_generator = VisualizationGenerator()
|
| 45 |
+
pdf_generator = PDFReportGenerator()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# Pydantic models
|
| 49 |
+
class TextInput(BaseModel):
|
| 50 |
+
text: str
|
| 51 |
+
user_name: Optional[str] = "User"
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class MultipleTexts(BaseModel):
|
| 55 |
+
texts: List[str]
|
| 56 |
+
user_name: Optional[str] = "User"
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class EmotionResponse(BaseModel):
|
| 60 |
+
emotions: dict
|
| 61 |
+
dominant_emotion: str
|
| 62 |
+
sentiment_score: float
|
| 63 |
+
sentiment_label: str
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@app.get("/")
|
| 67 |
+
async def root():
|
| 68 |
+
"""Root endpoint with API information"""
|
| 69 |
+
return {
|
| 70 |
+
"message": "Welcome to AI Mirror API",
|
| 71 |
+
"tagline": "Your words reflect more than you think",
|
| 72 |
+
"version": "1.0.0",
|
| 73 |
+
"developer": {
|
| 74 |
+
"name": "Sayed Mohd Zayeem Khateeb",
|
| 75 |
+
"email": "zayeem.s.khateeb@gmail.com",
|
| 76 |
+
"linkedin": "https://www.linkedin.com/in/zayeemkhateeb"
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
@app.get("/health")
|
| 82 |
+
async def health_check():
|
| 83 |
+
"""Health check endpoint"""
|
| 84 |
+
return {"status": "healthy", "service": "AI Mirror API"}
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
@app.post("/api/analyze-emotion", response_model=EmotionResponse)
|
| 88 |
+
async def analyze_emotion(input_data: TextInput):
|
| 89 |
+
"""
|
| 90 |
+
Analyze emotion from a single text input
|
| 91 |
+
"""
|
| 92 |
+
try:
|
| 93 |
+
logger.info(f"Analyzing emotion for text: {input_data.text[:50]}...")
|
| 94 |
+
result = emotion_detector.detect_emotion(input_data.text)
|
| 95 |
+
return result
|
| 96 |
+
except Exception as e:
|
| 97 |
+
logger.error(f"Error analyzing emotion: {str(e)}")
|
| 98 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
@app.post("/api/analyze-batch")
|
| 102 |
+
async def analyze_batch(input_data: MultipleTexts):
|
| 103 |
+
"""
|
| 104 |
+
Analyze emotions from multiple text inputs
|
| 105 |
+
"""
|
| 106 |
+
try:
|
| 107 |
+
logger.info(f"Analyzing batch of {len(input_data.texts)} texts")
|
| 108 |
+
results = []
|
| 109 |
+
for text in input_data.texts:
|
| 110 |
+
result = emotion_detector.detect_emotion(text)
|
| 111 |
+
results.append(result)
|
| 112 |
+
|
| 113 |
+
# Aggregate results
|
| 114 |
+
aggregated = emotion_detector.aggregate_emotions(results)
|
| 115 |
+
return aggregated
|
| 116 |
+
except Exception as e:
|
| 117 |
+
logger.error(f"Error analyzing batch: {str(e)}")
|
| 118 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
@app.post("/api/generate-insights")
|
| 122 |
+
async def generate_insights(input_data: TextInput):
|
| 123 |
+
"""
|
| 124 |
+
Generate AI-powered insights from text
|
| 125 |
+
"""
|
| 126 |
+
try:
|
| 127 |
+
logger.info("Generating AI insights...")
|
| 128 |
+
|
| 129 |
+
# First detect emotions
|
| 130 |
+
emotion_result = emotion_detector.detect_emotion(input_data.text)
|
| 131 |
+
|
| 132 |
+
# Generate insights using LLM
|
| 133 |
+
insights = await ai_insights.generate_insights(
|
| 134 |
+
text=input_data.text,
|
| 135 |
+
emotions=emotion_result['emotions'],
|
| 136 |
+
user_name=input_data.user_name
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
return {
|
| 140 |
+
"emotions": emotion_result,
|
| 141 |
+
"insights": insights
|
| 142 |
+
}
|
| 143 |
+
except Exception as e:
|
| 144 |
+
logger.error(f"Error generating insights: {str(e)}")
|
| 145 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
@app.post("/api/generate-art")
|
| 149 |
+
async def generate_art(input_data: TextInput):
|
| 150 |
+
"""
|
| 151 |
+
Generate AI artwork based on detected emotions
|
| 152 |
+
"""
|
| 153 |
+
try:
|
| 154 |
+
logger.info("Generating mood art...")
|
| 155 |
+
|
| 156 |
+
# Detect emotions
|
| 157 |
+
emotion_result = emotion_detector.detect_emotion(input_data.text)
|
| 158 |
+
|
| 159 |
+
# Generate art
|
| 160 |
+
art_result = await art_generator.generate_mood_art(
|
| 161 |
+
emotions=emotion_result['emotions'],
|
| 162 |
+
dominant_emotion=emotion_result['dominant_emotion']
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
return {
|
| 166 |
+
"emotions": emotion_result,
|
| 167 |
+
"artwork": art_result
|
| 168 |
+
}
|
| 169 |
+
except Exception as e:
|
| 170 |
+
logger.error(f"Error generating art: {str(e)}")
|
| 171 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
@app.post("/api/visualize")
|
| 175 |
+
async def create_visualizations(input_data: MultipleTexts):
|
| 176 |
+
"""
|
| 177 |
+
Create visualization charts from multiple texts
|
| 178 |
+
"""
|
| 179 |
+
try:
|
| 180 |
+
logger.info("Creating visualizations...")
|
| 181 |
+
|
| 182 |
+
# Analyze all texts
|
| 183 |
+
results = []
|
| 184 |
+
for text in input_data.texts:
|
| 185 |
+
result = emotion_detector.detect_emotion(text)
|
| 186 |
+
results.append(result)
|
| 187 |
+
|
| 188 |
+
# Generate visualizations
|
| 189 |
+
viz_data = viz_generator.create_visualizations(results)
|
| 190 |
+
|
| 191 |
+
return viz_data
|
| 192 |
+
except Exception as e:
|
| 193 |
+
logger.error(f"Error creating visualizations: {str(e)}")
|
| 194 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
@app.post("/api/generate-report")
|
| 198 |
+
async def generate_report(input_data: MultipleTexts):
|
| 199 |
+
"""
|
| 200 |
+
Generate a comprehensive PDF report
|
| 201 |
+
"""
|
| 202 |
+
try:
|
| 203 |
+
logger.info("Generating PDF report...")
|
| 204 |
+
|
| 205 |
+
# Analyze all texts
|
| 206 |
+
results = []
|
| 207 |
+
for text in input_data.texts:
|
| 208 |
+
result = emotion_detector.detect_emotion(text)
|
| 209 |
+
results.append(result)
|
| 210 |
+
|
| 211 |
+
# Aggregate emotions
|
| 212 |
+
aggregated = emotion_detector.aggregate_emotions(results)
|
| 213 |
+
|
| 214 |
+
# Generate insights
|
| 215 |
+
combined_text = " ".join(input_data.texts)
|
| 216 |
+
insights = await ai_insights.generate_insights(
|
| 217 |
+
text=combined_text,
|
| 218 |
+
emotions=aggregated['emotions'],
|
| 219 |
+
user_name=input_data.user_name
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
# Create visualizations
|
| 223 |
+
viz_data = viz_generator.create_visualizations(results)
|
| 224 |
+
|
| 225 |
+
# Generate PDF
|
| 226 |
+
pdf_path = pdf_generator.generate_report(
|
| 227 |
+
user_name=input_data.user_name,
|
| 228 |
+
emotions=aggregated,
|
| 229 |
+
insights=insights,
|
| 230 |
+
visualizations=viz_data
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
return FileResponse(
|
| 234 |
+
pdf_path,
|
| 235 |
+
media_type="application/pdf",
|
| 236 |
+
filename=f"ai_mirror_report_{input_data.user_name}.pdf"
|
| 237 |
+
)
|
| 238 |
+
except Exception as e:
|
| 239 |
+
logger.error(f"Error generating report: {str(e)}")
|
| 240 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
@app.post("/api/full-analysis")
|
| 244 |
+
async def full_analysis(input_data: MultipleTexts):
|
| 245 |
+
"""
|
| 246 |
+
Perform complete analysis including emotions, insights, art, and visualizations
|
| 247 |
+
"""
|
| 248 |
+
try:
|
| 249 |
+
logger.info("Performing full analysis...")
|
| 250 |
+
|
| 251 |
+
# Analyze all texts
|
| 252 |
+
results = []
|
| 253 |
+
for text in input_data.texts:
|
| 254 |
+
result = emotion_detector.detect_emotion(text)
|
| 255 |
+
results.append(result)
|
| 256 |
+
|
| 257 |
+
# Aggregate emotions
|
| 258 |
+
aggregated = emotion_detector.aggregate_emotions(results)
|
| 259 |
+
|
| 260 |
+
# Generate insights
|
| 261 |
+
combined_text = " ".join(input_data.texts)
|
| 262 |
+
insights = await ai_insights.generate_insights(
|
| 263 |
+
text=combined_text,
|
| 264 |
+
emotions=aggregated['emotions'],
|
| 265 |
+
user_name=input_data.user_name
|
| 266 |
+
)
|
| 267 |
+
|
| 268 |
+
# Generate art
|
| 269 |
+
art_result = await art_generator.generate_mood_art(
|
| 270 |
+
emotions=aggregated['emotions'],
|
| 271 |
+
dominant_emotion=aggregated['dominant_emotion']
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
# Create visualizations
|
| 275 |
+
viz_data = viz_generator.create_visualizations(results)
|
| 276 |
+
|
| 277 |
+
return {
|
| 278 |
+
"emotions": aggregated,
|
| 279 |
+
"insights": insights,
|
| 280 |
+
"artwork": art_result,
|
| 281 |
+
"visualizations": viz_data,
|
| 282 |
+
"text_count": len(input_data.texts)
|
| 283 |
+
}
|
| 284 |
+
except Exception as e:
|
| 285 |
+
logger.error(f"Error in full analysis: {str(e)}")
|
| 286 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
if __name__ == "__main__":
|
| 290 |
+
import uvicorn
|
| 291 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
requirements.txt
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi==0.104.1
|
| 2 |
+
uvicorn[standard]==0.24.0
|
| 3 |
+
python-multipart==0.0.6
|
| 4 |
+
transformers==4.35.2
|
| 5 |
+
torch==2.2.2
|
| 6 |
+
pandas==2.2.2
|
| 7 |
+
numpy==1.26.2
|
| 8 |
+
scikit-learn==1.3.2
|
| 9 |
+
textblob==0.17.1
|
| 10 |
+
nltk==3.8.1
|
| 11 |
+
spacy==3.7.2
|
| 12 |
+
plotly==5.18.0
|
| 13 |
+
matplotlib==3.8.2
|
| 14 |
+
seaborn==0.13.0
|
| 15 |
+
pillow==10.1.0
|
| 16 |
+
openai==1.3.7
|
| 17 |
+
google-generativeai==0.3.1
|
| 18 |
+
reportlab==4.0.7
|
| 19 |
+
wordcloud==1.9.3
|
| 20 |
+
python-dotenv==1.0.0
|
| 21 |
+
pydantic==2.5.2
|
| 22 |
+
httpx==0.25.2
|
| 23 |
+
aiofiles==23.2.1
|
| 24 |
+
|
| 25 |
+
dotenv
|
| 26 |
+
gradio-client
|