Spaces:
Running
Running
File size: 5,830 Bytes
9a255bf |
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
import gradio as gr
import pandas as pd
import logging
import sys
import os
from database import initialize_database, add_participant, get_participants_dataframe
# --- Logging Setup ---
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[logging.StreamHandler(sys.stdout)]
)
logger = logging.getLogger('app_simple')
# --- Initial Setup ---
logger.info("Initializing database...")
initialize_database()
# --- Gradio UI Functions ---
def register_participant(name, email, linkedin, background, goals):
"""Callback function to register a new participant."""
if not all([name, email]):
return "Please provide at least a name and email.", get_participants_dataframe()
participant_data = {
"name": name,
"email": email,
"linkedin_profile": linkedin,
"background": background,
"goals": goals
}
try:
add_participant(participant_data)
feedback = f"β
Success! Participant '{name}' registered."
logger.info(f"Registered new participant: {email}")
except Exception as e:
feedback = f"β Error! Could not register participant. Reason: {e}"
logger.error(f"Failed to register participant {email}: {e}")
return feedback, get_participants_dataframe()
def refresh_participants_list():
"""Callback to reload the participant data from the database."""
return get_participants_dataframe()
def mock_matching_process(organizer_criteria):
"""Mock function for the matching process (without using TinyCodeAgent)."""
participants_df = get_participants_dataframe()
if len(participants_df) < 2:
logger.warning("Matching process aborted: not enough participants.")
return "Cannot run matching with fewer than 2 participants."
# Create a simple mock output
result = f"""
## Team Matching Results
**Criteria used**: {organizer_criteria}
### Team 1
* **{participants_df['name'].iloc[0] if len(participants_df) > 0 else 'No participants'}**
* **{participants_df['name'].iloc[1] if len(participants_df) > 1 else 'No participants'}**
**Justification**: This is a mock team created for demonstration purposes.
### Team 2
* **{participants_df['name'].iloc[2] if len(participants_df) > 2 else 'No participants'}**
* **{participants_df['name'].iloc[3] if len(participants_df) > 3 else 'No participants'}**
**Justification**: This is another mock team created for demonstration purposes.
*Note: This is a simplified version without the AI matching. The full version would use TinyCodeAgent to create optimized teams.*
"""
return result
# --- Gradio App Definition ---
with gr.Blocks(theme=gr.themes.Soft(), title="HackBuddyAI (Simple)") as app:
gr.Markdown("# π€ HackBuddyAI (Simple Version)")
gr.Markdown("*This is a simplified version without the AI matching component.*")
with gr.Tabs():
with gr.TabItem("π€ Participant Registration"):
gr.Markdown("## Welcome, Participant!")
gr.Markdown("Fill out the form below to register for the hackathon.")
with gr.Row():
with gr.Column():
name_in = gr.Textbox(label="Full Name")
email_in = gr.Textbox(label="Email Address")
linkedin_in = gr.Textbox(label="LinkedIn Profile URL", placeholder="Optional")
with gr.Column():
background_in = gr.Textbox(label="Your Background & Skills", lines=5, placeholder="e.g., Python developer with 3 years of experience, specializing in Django and REST APIs...")
goals_in = gr.Textbox(label="Your Goals for this Hackathon", lines=5, placeholder="e.g., I want to learn about machine learning and work on a cool data visualization project...")
submit_button = gr.Button("Register", variant="primary")
registration_feedback = gr.Markdown()
with gr.TabItem("π Organizer Dashboard"):
gr.Markdown("## Welcome, Organizer!")
gr.Markdown("Here you can view registered participants and run the team matching process.")
with gr.Accordion("View Registered Participants", open=False):
refresh_button = gr.Button("π Refresh List")
participants_df_out = gr.DataFrame(value=get_participants_dataframe, interactive=False)
gr.Markdown("### Run Matching")
organizer_criteria_in = gr.Textbox(
label="Matching Criteria",
lines=4,
value="Create teams of 3. Try to balance skills in each team (e.g., frontend, backend, data).",
placeholder="Describe your ideal team composition..."
)
run_button = gr.Button("π Run Matching", variant="primary")
gr.Markdown("### π€ Matched Teams")
matching_results_out = gr.Markdown("Matching has not been run yet.")
# --- Event Handlers ---
submit_button.click(
fn=register_participant,
inputs=[name_in, email_in, linkedin_in, background_in, goals_in],
outputs=[registration_feedback, participants_df_out]
)
refresh_button.click(
fn=refresh_participants_list,
inputs=[],
outputs=[participants_df_out]
)
run_button.click(
fn=mock_matching_process,
inputs=[organizer_criteria_in],
outputs=[matching_results_out]
)
# --- Launching the App ---
if __name__ == "__main__":
try:
logger.info("Launching Gradio app (simple version)...")
# queue() is important for handling multiple users
app.queue().launch(share=False)
except KeyboardInterrupt:
logger.info("Gradio app shutting down.") |