Spaces:
Paused
A newer version of the Gradio SDK is available:
6.2.0
MATERIAL UPLOAD UI INTEGRATION GUIDE
Step-by-Step Instructions for Adding Material Upload Tab to Gradio App
π QUICK SUMMARY
What's Been Created:
- β
src/ai_engine/material_analyzer.py- Material analysis engine (600+ lines) - β
src/ai_engine/file_manager.py- File upload & auto-cleanup (450+ lines) - β
utils/material_upload_ui.py- UI helper functions (350+ lines) - β
Updated
src/ai_engine/__init__.py- Exports new classes
What You Need to Do:
- Add ONE new tab to the Gradio interface in
app.py - It will be Tab 6 (between Research and Settings tabs)
- Integration takes ~80 lines of code
π§ INTEGRATION STEPS
Step 1: Add Imports to app.py (Top of file)
Add these imports after the existing imports (around line 26):
# Material Upload & Analysis
from utils.material_upload_ui import (
analyze_uploaded_materials,
generate_from_material_analysis,
get_material_upload_instructions
)
Location: After line 24 (after other imports)
Step 2: Initialize Material Components
Add these initializations after the existing component initializations (around line 50-54):
# Material Upload & Analysis
from src.ai_engine import MaterialAnalyzer, MaterialProcessor, FileManager, FileCleanupScheduler
material_analyzer = MaterialAnalyzer()
material_processor = MaterialProcessor()
file_manager = FileManager()
cleanup_scheduler = FileCleanupScheduler(file_manager)
cleanup_scheduler.start()
Location: After line 54 (after other component initializations)
Step 3: Add the Material Upload Tab to Gradio UI
Add this code BEFORE the "βοΈ Advanced Settings" tab (around line 856).
Find this section in app.py (line ~856):
# ========== TAB 6: ADVANCED SETTINGS ==========
INSERT THIS CODE BEFORE THAT LINE:
# ========== TAB 6: MATERIAL UPLOAD & ANALYSIS ==========
with gr.Tab("π Material Analysis", id="tab_material"):
gr.Markdown(get_material_upload_instructions())
with gr.Row():
material_files = gr.File(
label="π€ Upload Lecture Materials (PDF, PowerPoint, Word, etc.)",
file_count="multiple",
file_types=[".pdf", ".docx", ".doc", ".txt", ".md", ".pptx", ".ppt"]
)
analyze_btn = gr.Button("π Analyze Materials", variant="primary", size="lg")
with gr.Row():
with gr.Column():
concepts_output = gr.Textbox(
label="π Key Concepts",
lines=8,
interactive=False
)
with gr.Column():
objectives_output = gr.Textbox(
label="π― Learning Objectives",
lines=8,
interactive=False
)
with gr.Row():
with gr.Column():
definitions_output = gr.Textbox(
label="π Key Definitions",
lines=8,
interactive=False
)
with gr.Column():
structure_output = gr.Textbox(
label="ποΈ Structure Analysis",
lines=8,
interactive=False
)
with gr.Row():
with gr.Column():
themes_output = gr.Textbox(
label="π Main Themes",
lines=8,
interactive=False
)
with gr.Column():
difficulty_output = gr.Textbox(
label="π Difficulty Level",
lines=8,
interactive=False
)
with gr.Row():
summary_output = gr.Textbox(
label="π Summary",
lines=4,
interactive=False
)
focus_output = gr.Textbox(
label="π Focus Areas",
lines=4,
interactive=False
)
# Analysis button click handler
analyze_btn.click(
fn=analyze_uploaded_materials,
inputs=[material_files],
outputs=[
concepts_output,
objectives_output,
definitions_output,
structure_output,
themes_output,
difficulty_output,
summary_output,
focus_output
]
)
# Optional: Generate documents from analysis
gr.Markdown("### π Generate Documents Based on Analysis")
with gr.Row():
doc_type = gr.Dropdown(
choices=["Study Guide", "Exam Notes", "Summary Sheet", "Concept Map"],
value="Study Guide",
label="Document Type"
)
doc_formats = gr.CheckboxGroup(
choices=["PDF", "Word", "Markdown"],
value=["PDF"],
label="Output Formats"
)
generate_btn = gr.Button("β¨ Generate Documents", variant="secondary")
generate_output = gr.Textbox(
label="Generation Status",
lines=5,
interactive=False
)
generate_btn.click(
fn=generate_from_material_analysis,
inputs=[
concepts_output,
objectives_output,
definitions_output,
doc_type,
doc_formats,
gr.State(generator) # Pass the content generator
],
outputs=[generate_output]
)
Location: Insert BEFORE line ~856 (before "TAB 6: ADVANCED SETTINGS")
Step 4: Rename Tab Numbers
After inserting the Material Upload tab, update the remaining tab numbers:
OLD:
# ========== TAB 6: ADVANCED SETTINGS ==========
NEW:
# ========== TAB 7: ADVANCED SETTINGS ==========
And similarly for "TAB 6: ABOUT & ETHICS" β "TAB 8: ABOUT & ETHICS"
π COMPLETE CODE INSERTION (Copy-Paste Ready)
If you want to copy the complete integration code at once:
FILE: app.py
ACTION: Add these 3 sections:
SECTION 1: Add to imports (around line 25)
# Material Upload & Analysis
from utils.material_upload_ui import (
analyze_uploaded_materials,
generate_from_material_analysis,
get_material_upload_instructions
)
SECTION 2: Add to initializations (around line 55)
# Material Upload & Analysis
from src.ai_engine import MaterialAnalyzer, MaterialProcessor, FileManager, FileCleanupScheduler
material_analyzer = MaterialAnalyzer()
material_processor = MaterialProcessor()
file_manager = FileManager()
cleanup_scheduler = FileCleanupScheduler(file_manager)
cleanup_scheduler.start()
SECTION 3: Add the Gradio tab (insert before line 856)
[See complete UI code above]
π QUICK START (Copy-Paste Instructions)
- Open:
app.pyin VS Code - Find: Line ~25 (imports section)
- Add: Material upload imports (SECTION 1)
- Find: Line ~55 (initializations)
- Add: Material component initializations (SECTION 2)
- Find: Line ~856 (look for "TAB 6: ADVANCED SETTINGS")
- Insert Before: Complete Material Upload tab code (SECTION 3)
- Update: Tab numbers for Settings and About tabs (TAB 6β7, TAB 7β8)
- Save and test
β VERIFICATION CHECKLIST
After integration, verify:
- App starts without errors
- All tabs visible in Gradio interface (should be 8 tabs now)
- Material Analysis tab loads properly
- Can upload files without errors
- "Analyze Materials" button works
- Analysis results display correctly
- Files are automatically deleted after processing
- No console errors or warnings
π TROUBLESHOOTING
Issue: "Cannot import MaterialAnalyzer"
Solution: Make sure src/ai_engine/__init__.py has the updated exports
Issue: "File upload not working"
Solution: Check that file types are supported (PDF, docx, txt, md, pptx)
Issue: "Analysis returns empty results"
Solution: Make sure the uploaded file has sufficient content (>50 characters)
Issue: "Memory usage high after uploads"
Solution: Files are automatically deleted - the FileCleanupScheduler handles cleanup
Issue: "Can't find utils/material_upload_ui.py"
Solution: Make sure the file was created in the utils directory
π TAB STRUCTURE AFTER INTEGRATION
Gradio Interface Tabs:
ββ Tab 1: Generate Document
ββ Tab 2: Data Visualization
ββ Tab 3: Templates & Formatting
ββ Tab 4: Quality Analysis
ββ Tab 5: AI Capabilities Research
ββ Tab 6: Material Upload & Analysis β NEW
ββ Tab 7: Advanced Settings (was Tab 6)
ββ Tab 8: About & Ethics (was Tab 7)
π USAGE SCENARIO
User Journey:
- Opens app in browser
- Clicks "π Material Analysis" tab
- Reads instructions about supported formats
- Clicks upload button, selects 3 PDFs (lecture notes, slides, supplementary material)
- Clicks "π Analyze Materials"
- System extracts and analyzes all 3 materials
- Results show:
- Key concepts from all materials combined
- Learning objectives
- Key definitions
- Structure information
- Main themes
- Difficulty level
- Suggested focus areas
- User reviews analysis
- Optional: Clicks "β¨ Generate Documents" to create study guide
- System auto-deletes uploaded files
- User continues with other features
π READY FOR SLIIT RESEARCH PROJECT
Your AI Academic Suite now includes:
- β Document generation from scratch
- β AI capability research analysis
- β Resource optimization for deployment
- β Material upload & analysis β THE FEATURE YOU REQUESTED
- β Auto-cleanup and privacy protection
Total Project Size: 55+ files, 7500+ lines of production code
Status: Ready for university research project deployment
Made with β€οΈ for SLIIT