Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,13 +48,16 @@ class HuggingFaceAIManager:
|
|
| 48 |
self.is_multimodal = False
|
| 49 |
|
| 50 |
# Real Gemma 3 models - prioritizing the actual Gemma 3 with multimodal capabilities
|
|
|
|
| 51 |
self.model_options = [
|
| 52 |
-
"google/gemma-
|
| 53 |
-
"
|
| 54 |
-
"google/gemma-3-1b-pt", # Gemma 3 text-only
|
| 55 |
-
"google/gemma-2-2b-it", # Fallback to Gemma 2
|
| 56 |
-
"microsoft/DialoGPT-medium", # Non-Gemma fallback 1
|
| 57 |
"distilgpt2", # Fallback 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
]
|
| 59 |
|
| 60 |
def load_model(self):
|
|
@@ -74,7 +77,11 @@ class HuggingFaceAIManager:
|
|
| 74 |
# Special handling for real Gemma 3 models
|
| 75 |
if "gemma-3" in model_name:
|
| 76 |
try:
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
if "4b-it" in model_name or "2b-it" in model_name:
|
| 79 |
print(f"π§ Loading Real Gemma 3 Multimodal: {model_name}")
|
| 80 |
from transformers import Gemma3ForConditionalGeneration, AutoProcessor
|
|
@@ -198,14 +205,21 @@ class HuggingFaceAIManager:
|
|
| 198 |
# Fallback to Gemma 2 or other models
|
| 199 |
elif "gemma-2" in model_name:
|
| 200 |
print(f"π Trying Gemma 2 fallback: {model_name}")
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
else:
|
| 211 |
# Standard loading for non-Gemma models
|
|
@@ -236,7 +250,8 @@ class HuggingFaceAIManager:
|
|
| 236 |
continue
|
| 237 |
|
| 238 |
print("β No models could be loaded, using template fallback mode")
|
| 239 |
-
print("π‘ Note:
|
|
|
|
| 240 |
return False
|
| 241 |
|
| 242 |
def generate_text(self, prompt, max_new_tokens=80, task_complexity="medium", image=None):
|
|
@@ -1823,17 +1838,19 @@ This content has been adapted for your learning style.
|
|
| 1823 |
|
| 1824 |
gr.Markdown("""
|
| 1825 |
# π AdaptLearn Enhanced - Next-Generation Adaptive Education
|
| 1826 |
-
### Hugging Face Spaces Edition - Powered
|
| 1827 |
|
| 1828 |
-
**π
|
| 1829 |
-
β’ π§ **
|
| 1830 |
-
β’ π€ **
|
| 1831 |
-
β’ ποΈ **Computer Vision Integration** -
|
| 1832 |
β’ π **Intelligent Learning Analytics** - AI-powered progress optimization
|
| 1833 |
-
β’ π **Adaptive Gamification** - Personalized motivation with
|
| 1834 |
-
β’ π **
|
| 1835 |
-
β’ π **24/7 Cloud Access** -
|
| 1836 |
-
β’ π± **Universal Compatibility** - Full
|
|
|
|
|
|
|
| 1837 |
""", elem_classes=["highlight-box"])
|
| 1838 |
|
| 1839 |
with gr.Row():
|
|
@@ -1880,14 +1897,12 @@ This content has been adapted for your learning style.
|
|
| 1880 |
with gr.Row():
|
| 1881 |
audio_input = gr.Audio(
|
| 1882 |
label="π€ Voice Recording (Optional)",
|
| 1883 |
-
type="filepath"
|
| 1884 |
-
info="Record your voice for emotion analysis"
|
| 1885 |
)
|
| 1886 |
|
| 1887 |
image_input = gr.Image(
|
| 1888 |
label="π· Photo for Real Gemma 3 Multimodal Analysis",
|
| 1889 |
-
type="numpy"
|
| 1890 |
-
info="Upload a photo for advanced multimodal AI analysis with Real Gemma 3"
|
| 1891 |
)
|
| 1892 |
|
| 1893 |
process_btn = gr.Button(
|
|
@@ -1908,10 +1923,9 @@ This content has been adapted for your learning style.
|
|
| 1908 |
gr.Markdown("### β¨ **PERSONALIZED LEARNING EXPERIENCE**")
|
| 1909 |
|
| 1910 |
adapted_content = gr.Textbox(
|
| 1911 |
-
label="π Your
|
| 1912 |
lines=10,
|
| 1913 |
-
interactive=False
|
| 1914 |
-
info="Content intelligently adapted by Real Gemma 3 AI with multimodal capabilities"
|
| 1915 |
)
|
| 1916 |
|
| 1917 |
with gr.Tabs():
|
|
@@ -2112,13 +2126,10 @@ def main():
|
|
| 2112 |
print("")
|
| 2113 |
|
| 2114 |
try:
|
| 2115 |
-
print("π¨ Creating
|
| 2116 |
demo = create_hugging_face_interface()
|
| 2117 |
|
| 2118 |
-
print("π Launching AdaptLearn Enhanced
|
| 2119 |
-
|
| 2120 |
-
# Check final AI status before launch
|
| 2121 |
-
print("π Final Real Gemma 3 system check complete - launching interface...")
|
| 2122 |
|
| 2123 |
# Launch with Hugging Face Spaces compatible settings
|
| 2124 |
demo.launch(
|
|
@@ -2135,7 +2146,10 @@ def main():
|
|
| 2135 |
|
| 2136 |
# Fallback launch
|
| 2137 |
try:
|
| 2138 |
-
demo
|
|
|
|
|
|
|
|
|
|
| 2139 |
except Exception as e2:
|
| 2140 |
print(f"β Fallback launch failed: {e2}")
|
| 2141 |
|
|
|
|
| 48 |
self.is_multimodal = False
|
| 49 |
|
| 50 |
# Real Gemma 3 models - prioritizing the actual Gemma 3 with multimodal capabilities
|
| 51 |
+
# Note: These require authentication, fallbacks included for public access
|
| 52 |
self.model_options = [
|
| 53 |
+
"google/gemma-2-2b-it", # Primary: Gemma 2 (publicly available)
|
| 54 |
+
"microsoft/DialoGPT-medium", # Reliable fallback 1
|
|
|
|
|
|
|
|
|
|
| 55 |
"distilgpt2", # Fallback 2
|
| 56 |
+
"gpt2", # Final fallback
|
| 57 |
+
# Commented out until authentication is available:
|
| 58 |
+
# "google/gemma-3-4b-it", # Real Gemma 3 multimodal (requires auth)
|
| 59 |
+
# "google/gemma-3-2b-it", # Alternative Gemma 3 (requires auth)
|
| 60 |
+
# "google/gemma-3-1b-pt", # Gemma 3 text-only (requires auth)
|
| 61 |
]
|
| 62 |
|
| 63 |
def load_model(self):
|
|
|
|
| 77 |
# Special handling for real Gemma 3 models
|
| 78 |
if "gemma-3" in model_name:
|
| 79 |
try:
|
| 80 |
+
print(f"β οΈ Gemma 3 requires authentication - skipping {model_name}")
|
| 81 |
+
print("π‘ To use Gemma 3, add your HF token to the Space secrets")
|
| 82 |
+
continue
|
| 83 |
+
|
| 84 |
+
# Real Gemma 3 multimodal loading (requires authentication)
|
| 85 |
if "4b-it" in model_name or "2b-it" in model_name:
|
| 86 |
print(f"π§ Loading Real Gemma 3 Multimodal: {model_name}")
|
| 87 |
from transformers import Gemma3ForConditionalGeneration, AutoProcessor
|
|
|
|
| 205 |
# Fallback to Gemma 2 or other models
|
| 206 |
elif "gemma-2" in model_name:
|
| 207 |
print(f"π Trying Gemma 2 fallback: {model_name}")
|
| 208 |
+
try:
|
| 209 |
+
self.pipeline = pipeline(
|
| 210 |
+
"text-generation",
|
| 211 |
+
model=model_name,
|
| 212 |
+
device_map="auto" if torch.cuda.is_available() else None,
|
| 213 |
+
torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
|
| 214 |
+
trust_remote_code=True
|
| 215 |
+
)
|
| 216 |
+
self.is_multimodal = False
|
| 217 |
+
print(f"β
Gemma 2 loaded successfully: {model_name}")
|
| 218 |
+
|
| 219 |
+
except Exception as gemma2_error:
|
| 220 |
+
print(f"β οΈ Gemma 2 loading failed: {gemma2_error}")
|
| 221 |
+
print("π‘ Gemma 2 also requires authentication - using open models")
|
| 222 |
+
continue
|
| 223 |
|
| 224 |
else:
|
| 225 |
# Standard loading for non-Gemma models
|
|
|
|
| 250 |
continue
|
| 251 |
|
| 252 |
print("β No models could be loaded, using template fallback mode")
|
| 253 |
+
print("π‘ Note: Gemma models require authentication. Add HF token to Space secrets for access.")
|
| 254 |
+
print("π Using intelligent template system for educational adaptation")
|
| 255 |
return False
|
| 256 |
|
| 257 |
def generate_text(self, prompt, max_new_tokens=80, task_complexity="medium", image=None):
|
|
|
|
| 1838 |
|
| 1839 |
gr.Markdown("""
|
| 1840 |
# π AdaptLearn Enhanced - Next-Generation Adaptive Education
|
| 1841 |
+
### Hugging Face Spaces Edition - AI-Powered Learning System
|
| 1842 |
|
| 1843 |
+
**π INTELLIGENT AI FEATURES:**
|
| 1844 |
+
β’ π§ **Advanced AI Engine** - DialoGPT and fallback models for reliable content generation
|
| 1845 |
+
β’ π€ **Smart Audio Analysis** - Real-time emotion and engagement detection
|
| 1846 |
+
β’ ποΈ **Computer Vision Integration** - Visual attention and engagement monitoring
|
| 1847 |
β’ π **Intelligent Learning Analytics** - AI-powered progress optimization
|
| 1848 |
+
β’ π **Adaptive Gamification** - Personalized motivation with AI feedback
|
| 1849 |
+
β’ π **Robust Fallback Systems** - Guaranteed functionality with intelligent templates
|
| 1850 |
+
β’ π **24/7 Cloud Access** - Reliable AI power available anywhere, anytime
|
| 1851 |
+
β’ π± **Universal Compatibility** - Full experience on all devices
|
| 1852 |
+
|
| 1853 |
+
**π‘ Gemma Access:** To unlock Real Gemma 3 capabilities, add your Hugging Face token to Space secrets
|
| 1854 |
""", elem_classes=["highlight-box"])
|
| 1855 |
|
| 1856 |
with gr.Row():
|
|
|
|
| 1897 |
with gr.Row():
|
| 1898 |
audio_input = gr.Audio(
|
| 1899 |
label="π€ Voice Recording (Optional)",
|
| 1900 |
+
type="filepath"
|
|
|
|
| 1901 |
)
|
| 1902 |
|
| 1903 |
image_input = gr.Image(
|
| 1904 |
label="π· Photo for Real Gemma 3 Multimodal Analysis",
|
| 1905 |
+
type="numpy"
|
|
|
|
| 1906 |
)
|
| 1907 |
|
| 1908 |
process_btn = gr.Button(
|
|
|
|
| 1923 |
gr.Markdown("### β¨ **PERSONALIZED LEARNING EXPERIENCE**")
|
| 1924 |
|
| 1925 |
adapted_content = gr.Textbox(
|
| 1926 |
+
label="π Your AI Personalized Content",
|
| 1927 |
lines=10,
|
| 1928 |
+
interactive=False
|
|
|
|
| 1929 |
)
|
| 1930 |
|
| 1931 |
with gr.Tabs():
|
|
|
|
| 2126 |
print("")
|
| 2127 |
|
| 2128 |
try:
|
| 2129 |
+
print("π¨ Creating Hugging Face Spaces interface...")
|
| 2130 |
demo = create_hugging_face_interface()
|
| 2131 |
|
| 2132 |
+
print("π Launching AdaptLearn Enhanced on Hugging Face Spaces...")
|
|
|
|
|
|
|
|
|
|
| 2133 |
|
| 2134 |
# Launch with Hugging Face Spaces compatible settings
|
| 2135 |
demo.launch(
|
|
|
|
| 2146 |
|
| 2147 |
# Fallback launch
|
| 2148 |
try:
|
| 2149 |
+
if 'demo' in locals():
|
| 2150 |
+
demo.launch()
|
| 2151 |
+
else:
|
| 2152 |
+
print("β Demo not created - check interface creation")
|
| 2153 |
except Exception as e2:
|
| 2154 |
print(f"β Fallback launch failed: {e2}")
|
| 2155 |
|