📊 Building AI Analysis Tool
Xây dựng công cụ phân tích data/documents với AI.
Project Overview
What We'll Build
Text
1AI Analysis Tool Features:2- Upload documents/data3- AI-powered analysis4- Insights & summaries5- Export reports6- History trackingAnalysis Types
Text
11. Text Analysis2 - Sentiment3 - Key topics4 - Summary5 62. Data Analysis7 - Patterns8 - Trends9 - Anomalies10 113. Document Analysis12 - Extract info13 - Q&A on content14 - SummarizeUI Design
Text
1┌────────────────────────────────────────────────┐2│ 📊 AI Analyzer [History] 👤│3├────────────────────────────────────────────────┤4│ │5│ ┌─────────────────────────────────────────┐ │6│ │ 📁 Drop files here or [Browse] │ │7│ │ PDF, TXT, CSV, DOCX (max 10MB) │ │8│ └─────────────────────────────────────────┘ │9│ │10│ Or paste text directly: │11│ ┌─────────────────────────────────────────┐ │12│ │ │ │13│ │ │ │14│ └─────────────────────────────────────────┘ │15│ │16│ Analysis Type: [Full Analysis ▼] │17│ │18│ [🔍 Analyze Now] │19│ │20├────────────────────────────────────────────────┤21│ Results │22│ ┌─────────────────────────────────────────┐ │23│ │ Summary │ │24│ │ ───────── │ │25│ │ This document discusses... │ │26│ │ │ │27│ │ Key Points │ │28│ │ ───────── │ │29│ │ • Point 1 │ │30│ │ • Point 2 │ │31│ │ │ │32│ │ Sentiment: Positive (85%) │ │33│ └─────────────────────────────────────────┘ │34│ │35│ [📥 Export PDF] [💾 Save] [📋 Copy] │36└────────────────────────────────────────────────┘Database Design
Text
1Analysis:2- title (text)3- input_text (text)4- input_file (file)5- analysis_type (text)6- results (text/JSON)7- summary (text)8- sentiment (text)9- sentiment_score (number)10- key_points (list of texts)11- created_date (date)12- user (User)13- is_favorite (yes/no)File Upload Setup
Bubble File Uploader
Text
1File Uploader element:2- Accept: .txt, .pdf, .csv, .docx3- Max size: 10MB4- Dynamic: Store as private fileReading File Content
File Processing
Text
1Bubble limitations:2- Can't directly read PDF/DOCX content3- Need external service4 5Options:61. Use text files only (simplest)72. Use API for PDF parsing83. Third-party integration (DocParser)94. Backend serviceSimple Text Upload
Text
1For MVP:2- Accept .txt and .csv only3- Read content directly4- Or copy-paste text inputAnalysis Prompts
Full Analysis Prompt
Text
1System:2"You are an expert analyst. Analyze content thoroughly 3and provide structured insights."4 5User:6"Analyze this content and provide:71. Brief Summary (2-3 sentences)82. Key Points (5 bullet points)93. Sentiment (positive/negative/neutral + confidence %)104. Main Topics (list)115. Actionable Insights (if applicable)12 13Format as JSON:14{15 'summary': '...',16 'key_points': ['...', '...'],17 'sentiment': {'label': '...', 'score': 0.0},18 'topics': ['...'],19 'insights': ['...']20}21 22Content:23{content}"Sentiment Analysis Prompt
Text
1"Analyze the sentiment of this text.2Return JSON:3{4 'sentiment': 'positive/negative/neutral/mixed',5 'score': 0.0-1.0,6 'emotions': ['emotion1', 'emotion2'],7 'explanation': 'brief reason'8}9 10Text: {content}"Summary Prompt
Text
1"Summarize this content:21. One-sentence overview32. Detailed summary (100 words)43. Key takeaways (3 points)5 6Content: {content}"Analysis Workflow
Text
1Button "Analyze" clicked:2 3Step 1: Get content4- If file uploaded: read file content5- Else: use text input6- Validate not empty7 8Step 2: Set loading state9- Show "Analyzing..."10- Disable button11 12Step 3: Select prompt13- Based on analysis_type dropdown14 15Step 4: Call OpenAI API16- With appropriate prompt17- Send content18 19Step 5: Parse response20- Extract JSON21- Handle errors22 23Step 6: Display results24- Populate result sections25- Show visualizations26 27Step 7: Save to database28- Create Analysis record29- Store all results30 31Step 8: Clear loadingDisplaying Results
Summary Section
Text
1Group "Summary":2- Text: results:summary3- Visible when results existKey Points
Text
1Repeating Group:2- Type: text3- Source: results:key_points4- Cell: bullet + textSentiment Visualization
Text
1Visual components:21. Label badge (color-coded)3 - Positive: green4 - Negative: red5 - Neutral: gray6 72. Progress bar8 - Width: sentiment_score * 100%9 103. Emoji indicator11 - 😊 / 😐 / 😢Topics Tags
Text
1Repeating Group (horizontal):2- Type: text3- Source: results:topics4- Cell: chip/tag styleCSV Data Analysis
Parse CSV
Text
1For CSV files:21. Read file content32. Parse rows and columns43. Send structure info to AIAnalysis Prompt for Data
Text
1"Analyze this CSV data:2Columns: {column_names}3Sample rows: {first_10_rows}4Total rows: {row_count}5 6Provide:71. Data overview82. Column descriptions93. Key patterns or trends104. Data quality issues115. Recommendations"Document Q&A Feature
Ask Questions
Text
1After analysis:2- Show question input3- "Ask a question about this document"4- AI answers based on contentImplementation
Text
1Q&A Prompt:2"Based on this document:3{document_content}4 5Answer this question:6{user_question}7 8Be specific and cite relevant parts."Export Features
Copy Results
Text
1Format for clipboard:2"3ANALYSIS RESULTS4================5Summary: {summary}6 7Key Points:8- {point1}9- {point2}10...11 12Sentiment: {sentiment} ({score}%)13"Export as PDF
Text
1Options:21. Use PDF generation plugin32. Create HTML, convert to PDF43. Third-party service (PDFMonkey)History Page
Layout
Text
1┌────────────────────────────────────────┐2│ Analysis History │3├────────────────────────────────────────┤4│ ┌────────────────────────────────────┐ │5│ │ 📄 Q3 Report Analysis │ │6│ │ Dec 15, 2024 | Full Analysis │ │7│ │ Sentiment: Positive │ │8│ │ [View] [Export] [Delete] │ │9│ └────────────────────────────────────┘ │10└────────────────────────────────────────┘View Previous Analysis
Text
1Click on history item:21. Navigate to analysis page32. Load saved results43. Display without re-analyzingError Handling
Handle Errors
Text
1Common issues:2 31. File too large4 "File exceeds 10MB limit. Please use a smaller file."5 62. Unsupported format7 "This file type is not supported. Please use TXT or CSV."8 93. Content too long10 "Content is too long. Please use text under 50,000 characters."11 124. API error13 "Analysis failed. Please try again."Performance Tips
Optimize Performance
Text
11. Truncate very long content2 - Send first 50,000 characters3 - Or summarize in chunks4 52. Show partial results6 - Display as available7 - Don't wait for everything8 93. Cache similar analyses10 - Hash input content11 - Return cached if exists12 134. Background processing14 - For large files15 - Email results when doneTesting Checklist
Test Your Tool
Text
1☐ Text input analysis works2☐ File upload works (txt, csv)3☐ All analysis types work4☐ Results display correctly5☐ Sentiment visualization works6☐ Copy results works7☐ Save to history works8☐ View history works9☐ Error handling works10☐ Loading states showBài Tập
Complete Project
Build AI Analysis Tool:
- Create database structure
- Build upload/input UI
- Implement analysis prompts
- Create analysis workflow
- Display results with visualizations
- Add sentiment indicator
- Implement Q&A feature
- Build history page
- Add export options
- Test with various content
Tiếp theo: Bài 12 - User Authentication & Payments
