shegga's picture
๐ŸŽ‰ Major Refactor: Modular Architecture with Automatic Fine-Tuning
b8ae42e
"""
Model Information Page for Vietnamese Sentiment Analysis
"""
import gradio as gr
import time
def create_model_info_page(app_instance):
"""Create the model information tab"""
def update_memory_info():
"""Update memory usage information"""
if app_instance and app_instance.model_loaded:
memory_usage = app_instance.get_memory_usage()
return f"Memory usage: {memory_usage:.1f}MB used"
return "Memory usage: 0MB used"
def manual_memory_cleanup():
"""Manual memory cleanup"""
if app_instance and app_instance.model_loaded:
app_instance.cleanup_memory()
memory_usage = app_instance.get_memory_usage()
return f"Memory cleaned. Current usage: {memory_usage:.1f}MB"
return "App not initialized"
# Model Info Tab
with gr.Tab("โ„น๏ธ Model Information"):
gr.Markdown(f"""
## ๐Ÿค– Model Details
**Model Architecture:** Transformer-based sequence classification
**Base Model:** {app_instance.finetuned_model}
**Languages:** Vietnamese (optimized)
**Labels:** Negative, Neutral, Positive
## ๐Ÿ“Š Performance Metrics
- **Processing Speed:** ~100ms per text
- **Max Sequence Length:** 512 tokens
- **Memory Limit:** 8GB
## ๐Ÿ’ก Usage Tips
- Enter clear, grammatically correct Vietnamese text
- Longer texts (20-200 words) work best
- The model handles various Vietnamese dialects
- Confidence scores indicate prediction certainty
## ๐Ÿ›ก๏ธ Memory Management
- **Automatic Cleanup:** Memory is cleaned after each prediction
- **Batch Limits:** Maximum 10 texts per batch to prevent overflow
- **Memory Monitoring:** Real-time memory usage tracking
- **GPU Optimization:** CUDA cache clearing when available
## โš ๏ธ Performance Notes
- If you encounter memory errors, try reducing batch size
- Use the Memory Cleanup button if needed
- Monitor memory usage in the Batch Analysis tab
- Model loaded directly from Hugging Face Hub (no local training required)
""")
with gr.Row():
memory_info = gr.Textbox(
label="Memory Usage",
value="Memory usage: 0MB used",
interactive=False
)
memory_cleanup_btn = gr.Button("๐Ÿงน Memory Cleanup", variant="secondary")
# Connect memory cleanup event
memory_cleanup_btn.click(
fn=manual_memory_cleanup,
outputs=[memory_info]
)
return memory_cleanup_btn, memory_info