Spaces:
Runtime error
Runtime error
File size: 2,681 Bytes
b8ae42e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | """
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 |