Spaces:
Sleeping
Sleeping
File size: 2,302 Bytes
064ad85 6487907 064ad85 6487907 064ad85 6487907 064ad85 6487907 064ad85 6487907 064ad85 6487907 064ad85 6487907 064ad85 6487907 064ad85 |
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 |
import os
from huggingface_hub import InferenceClient
def generate_dropout_insights(input_values, risk_factors, label):
"""
Generates structured dropout risk insights using AI, ensuring Unicode-safe text for PDFs.
"""
excluded_fields = {"roll_no", "semester", "degree"} # Fields to exclude from analysis
# Filter only relevant input values
filtered_input_values = {key: value for key, value in input_values.items() if key not in excluded_fields}
# Map input values to their corresponding risk factors
risk_mapping = {key: risk for key, risk in zip(filtered_input_values.keys(), risk_factors)}
# Construct message for AI model
formatted_input = "\n".join([f"{key}: {value} (Risk: {risk})" for key, (value, risk) in zip(filtered_input_values.keys(), zip(filtered_input_values.values(), risk_factors))])
messages = [
{
"role": "user",
"content": f"""
Generate a detailed dropout risk analysis report based on the following data:
{formatted_input}
Format the response as:
## Analysis of Student Dropout Risk
Overall Risk Level: {label}
### ๐ข Strengths:
List areas where the student is performing well:
{{strengths}}
### ๐ด Concerns:
Identify factors that increase dropout risk:
{{concerns}}
### ๐ Action Plan for Improvement:
Provide targeted **solutions** based on the student's **weak areas**:
{{recommendations}}
## ๐ Final Recommendation:
{{overall_recommendation}}
"""
}
]
client = InferenceClient(
provider="nebius",
api_key=os.getenv("HUGGINGFACE_API_TOKEN")
)
stream = client.chat.completions.create(
model="deepseek-ai/DeepSeek-R1",
messages=messages,
temperature=0.5,
max_tokens=2048,
top_p=0.7,
stream=True
)
# Collect and return the generated report
report = ""
for chunk in stream:
report += chunk.choices[0].delta.content
return report
|