Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -152,6 +152,17 @@ def train_model():
|
|
| 152 |
except Exception as e:
|
| 153 |
return f"β Error training model: {str(e)}"
|
| 154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
# Create Gradio interface
|
| 156 |
def create_interface():
|
| 157 |
with gr.Blocks(title="Course AI Recommender", theme=gr.themes.Soft()) as demo:
|
|
@@ -193,6 +204,8 @@ def create_interface():
|
|
| 193 |
get_recommendations_btn = gr.Button("π― Get Recommendations", variant="primary")
|
| 194 |
|
| 195 |
train_model_btn = gr.Button("π€ Train Model", variant="secondary")
|
|
|
|
|
|
|
| 196 |
|
| 197 |
with gr.Column(scale=1):
|
| 198 |
gr.Markdown("### π Top 3 Course Recommendations")
|
|
@@ -237,6 +250,12 @@ def create_interface():
|
|
| 237 |
label="Rating Feedback",
|
| 238 |
interactive=False
|
| 239 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
# Event handlers
|
| 242 |
get_recommendations_btn.click(
|
|
@@ -256,6 +275,11 @@ def create_interface():
|
|
| 256 |
outputs=[gr.Textbox(label="Training Status", interactive=False)]
|
| 257 |
)
|
| 258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
# Add some example inputs
|
| 260 |
gr.Markdown("""
|
| 261 |
### π‘ Example Inputs
|
|
|
|
| 152 |
except Exception as e:
|
| 153 |
return f"β Error training model: {str(e)}"
|
| 154 |
|
| 155 |
+
def get_available_courses_info():
|
| 156 |
+
"""Get information about available courses from database"""
|
| 157 |
+
try:
|
| 158 |
+
courses = db_connection.get_available_courses()
|
| 159 |
+
if courses:
|
| 160 |
+
return f"π Available courses in database: {len(courses)}\n\n" + "\n".join([f"β’ {course}" for course in courses[:10]]) + (f"\n... and {len(courses)-10} more" if len(courses) > 10 else "")
|
| 161 |
+
else:
|
| 162 |
+
return "π No courses found in database. Please check the /courses endpoint."
|
| 163 |
+
except Exception as e:
|
| 164 |
+
return f"β Error fetching courses: {str(e)}"
|
| 165 |
+
|
| 166 |
# Create Gradio interface
|
| 167 |
def create_interface():
|
| 168 |
with gr.Blocks(title="Course AI Recommender", theme=gr.themes.Soft()) as demo:
|
|
|
|
| 204 |
get_recommendations_btn = gr.Button("π― Get Recommendations", variant="primary")
|
| 205 |
|
| 206 |
train_model_btn = gr.Button("π€ Train Model", variant="secondary")
|
| 207 |
+
|
| 208 |
+
show_courses_btn = gr.Button("π Show Available Courses", variant="secondary")
|
| 209 |
|
| 210 |
with gr.Column(scale=1):
|
| 211 |
gr.Markdown("### π Top 3 Course Recommendations")
|
|
|
|
| 250 |
label="Rating Feedback",
|
| 251 |
interactive=False
|
| 252 |
)
|
| 253 |
+
|
| 254 |
+
courses_info = gr.Textbox(
|
| 255 |
+
label="Available Courses",
|
| 256 |
+
lines=8,
|
| 257 |
+
interactive=False
|
| 258 |
+
)
|
| 259 |
|
| 260 |
# Event handlers
|
| 261 |
get_recommendations_btn.click(
|
|
|
|
| 275 |
outputs=[gr.Textbox(label="Training Status", interactive=False)]
|
| 276 |
)
|
| 277 |
|
| 278 |
+
show_courses_btn.click(
|
| 279 |
+
fn=get_available_courses_info,
|
| 280 |
+
outputs=[courses_info]
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
# Add some example inputs
|
| 284 |
gr.Markdown("""
|
| 285 |
### π‘ Example Inputs
|