ai_workflows / tasks /create_learning_profile.py
Quizra
add code to spin streamlit ui
f8558a4
raw
history blame
1.31 kB
import json
import streamlit as st
from crewai import Task
from crewai.tasks.task_output import TaskOutput
from pydantic import BaseModel
from typing import List
from agents.learning_profiler import learning_profiler
class Topic(BaseModel):
name: str
insights: List[str]
class LearningProfile(BaseModel):
topics_of_interests: List[str]
learnings: List[Topic]
def callback_function(output: TaskOutput):
st.markdown("### Learning profile of the user:")
data=json.loads(output.exported_output)
st.markdown(f"**topics_of_interests:** {data['topics_of_interests'][0]}")
st.markdown(f"**learnings:**")
for topic in data['learnings']:
st.markdown(f"*{topic['name']}*:{topic['insights'][0]}")
learning_profile_task = Task(
description=(
"Create a Learning profile of the user based on "
"the following articles and insights he has read in the past: \n"
"{previous_article_insights}"
),
expected_output=(
"A structured learning profile of the user with his interests, topics he has read about "
"and insights he has captured on the topics."
),
agent=learning_profiler,
output_json=LearningProfile,
output_file="learning_profile.json",
async_execution=False,
callback=callback_function
)