Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added submissions/T039_BlueScreeners/T039.pptx
Binary file not shown.
61 changes: 61 additions & 0 deletions submissions/T039_BlueScreeners/ai_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# ai_services.py
import joblib

# --- Placeholder functions for your ML models ---
# You will replace these with the actual code from your model files.

def load_prediction_model(path='ml_models/trained_model.pkl'):
"""Loads the trained risk prediction model."""
try:
model = joblib.load(path)
print("Prediction model loaded successfully.")
return model
except FileNotFoundError:
print("Prediction model file not found. Please check the path.")
return None

def get_risk_prediction(model, student_data):
"""
Takes the model and student data to return a risk prediction.
- student_data should be a list or array in the format your model expects,
e.g., [attendance_percentage, avg_assignment_score, avg_quiz_score]
"""
if model is None:
return "Model not loaded", 0.0

# This is an example; you'll need to format the data exactly as your model was trained
# prediction = model.predict([student_data])
# probability = model.predict_proba([student_data])

# Returning mock data for now
risk_level = "High" if student_data[0] < 75 else "Low"
risk_score = 0.85 if risk_level == "High" else 0.25

return risk_level, risk_score

def generate_quiz_questions(topic, level='hard'):
"""
Calls your quiz_generator_v3.py logic.
"""
# Import or call your quiz generator function here
print(f"Generating {level} quiz for topic: {topic}")
# Returning mock data
return [
{
"question": f"What is the capital of {topic}?",
"options": ["Option A", "Option B", "Option C", "Correct Answer"],
"correct_answer": "Correct Answer"
}
]

def get_chatbot_response(user_query, history=None):
"""
Calls your chatbot_v2.py logic.
"""
# Import or call your chatbot function here
print(f"Chatbot processing query: {user_query}")
# Returning a simple response
if "schedule" in user_query.lower():
return "Your class schedule can be found on the student portal under 'My Schedule'."
else:
return "I am a helpful assistant. How can I help you with your academic questions today?"
46 changes: 46 additions & 0 deletions submissions/T039_BlueScreeners/chatbot_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from transformers import pipeline

def start_chat_v2():
"""
Initializes and runs a conversational chatbot.
This version manually manages the chat history to avoid import issues.
"""
print("🤖 Initializing chatbot... This may take a moment.")
chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")
print("✅ Chatbot is ready! Type 'exit' to end the conversation.")
print("-" * 30)

# We will use simple lists to keep track of the conversation history
chat_history = {
"past_user_inputs": [],
"generated_responses": []
}

while True:
user_input = input(">> You: ")

if user_input.lower() in ["exit", "quit"]:
print("👋 Goodbye!")
break

# Manually build the conversation object the pipeline expects
conversation = {
"past_user_inputs": chat_history["past_user_inputs"],
"generated_responses": chat_history["generated_responses"],
"text": user_input
}

# Get the response
result = chatbot(conversation)

# Print the latest response from the bot
bot_response = result["generated_responses"][-1]
print(f">> Bot: {bot_response}")

# Update our history with the latest turn
chat_history["past_user_inputs"].append(user_input)
chat_history["generated_responses"].append(bot_response)

# --- Start the Chatbot ---
if __name__ == "__main__":
start_chat_v2()
45 changes: 45 additions & 0 deletions submissions/T039_BlueScreeners/encode_faces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# encode_faces.py (Bypassing OpenCV)
import face_recognition
import pickle
import os

# Path to the directory where student images are stored
folderPath = 'student_images'
pathList = os.listdir(folderPath)
print(f"Found files: {pathList}")

encodeListKnown = []
studentUsernames = []

print("\nStarting encoding process using the direct loader...")
for path in pathList:
username = os.path.splitext(path)[0]
try:
# Load the image file directly using face_recognition's built-in loader
# This function handles all the necessary conversions automatically
print(f"Processing image for '{username}'...")
image = face_recognition.load_image_file(os.path.join(folderPath, path))

# Get face encodings from the image
encodings = face_recognition.face_encodings(image)

if encodings:
# Use the first face found in the image
encodeListKnown.append(encodings[0])
studentUsernames.append(username)
print(f"--> Successfully encoded face for: '{username}'")
else:
print(f"Warning: No face was found in the image for '{username}'. Skipping.")

except Exception as e:
print(f"!!! An unexpected error occurred while processing '{username}': {e}")

# Save the data only if at least one face was successfully encoded
if encodeListKnown:
encodeData = [studentUsernames, encodeListKnown]

with open('EncodeFile.p', 'wb') as file:
pickle.dump(encodeData, file)
print("\nEncoding Complete. Face data saved to EncodeFile.p")
else:
print("\nEncoding failed. No faces were successfully encoded.")
39 changes: 39 additions & 0 deletions submissions/T039_BlueScreeners/import_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# import_data.py
import csv
from server import app, db, User, Student, Teacher # Imports from the configured server file
from werkzeug.security import generate_password_hash

def import_csv_data():
with app.app_context():
print("Dropping all tables...")
db.drop_all()
print("Creating all tables...")
db.create_all()

with open('student_data.csv', newline='') as csvfile:
reader = csv.DictReader(csvfile)
print("Starting data import...")
for row in reader:
if User.query.filter_by(username=row['username']).first():
print(f"User '{row['username']}' already exists. Skipping.")
continue

hashed_password = generate_password_hash(row['password'])
new_user = User(username=row['username'], password_hash=hashed_password, role=row['role'])
db.session.add(new_user)
db.session.commit()

if new_user.role == 'student':
new_profile = Student(full_name=row['full_name'], user_id=new_user.id)
db.session.add(new_profile)
elif new_user.role == 'teacher':
new_profile = Teacher(full_name=row['full_name'], user_id=new_user.id)
db.session.add(new_profile)

print(f"Added user: {new_user.username} (Role: {new_user.role})")

db.session.commit()
print("\nData import complete!")

if __name__ == '__main__':
import_csv_data()
Binary file not shown.
Binary file not shown.
Binary file not shown.
46 changes: 46 additions & 0 deletions submissions/T039_BlueScreeners/ml_models/chatbot_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from transformers import pipeline

def start_chat_v2():
"""
Initializes and runs a conversational chatbot.
This version manually manages the chat history to avoid import issues.
"""
print("🤖 Initializing chatbot... This may take a moment.")
chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")
print("✅ Chatbot is ready! Type 'exit' to end the conversation.")
print("-" * 30)

# We will use simple lists to keep track of the conversation history
chat_history = {
"past_user_inputs": [],
"generated_responses": []
}

while True:
user_input = input(">> You: ")

if user_input.lower() in ["exit", "quit"]:
print("👋 Goodbye!")
break

# Manually build the conversation object the pipeline expects
conversation = {
"past_user_inputs": chat_history["past_user_inputs"],
"generated_responses": chat_history["generated_responses"],
"text": user_input
}

# Get the response
result = chatbot(conversation)

# Print the latest response from the bot
bot_response = result["generated_responses"][-1]
print(f">> Bot: {bot_response}")

# Update our history with the latest turn
chat_history["past_user_inputs"].append(user_input)
chat_history["generated_responses"].append(bot_response)

# --- Start the Chatbot ---
if __name__ == "__main__":
start_chat_v2()
27 changes: 27 additions & 0 deletions submissions/T039_BlueScreeners/ml_models/chatbot_v2_web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from transformers import pipeline

class WebChatbot:
def __init__(self):
"""
Initializes the text-generation chatbot pipeline and chat history.
"""
self.chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
self.chat_history = []

def get_response(self, user_input):
"""
Accepts user input string, returns bot response string and updates chat history.
"""
# Append user input to chat history
self.chat_history.append(user_input)

# Generate response using text-generation pipeline
# Join chat history as context
context = " ".join(self.chat_history[-5:]) # last 5 messages as context
outputs = self.chatbot(context, max_length=100, num_return_sequences=1)
bot_response = outputs[0]['generated_text'][len(context):].strip()

# Append bot response to chat history
self.chat_history.append(bot_response)

return bot_response, self.chat_history
Loading