Skip to content

Commit

Permalink
use json data for refrence in generating critical analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudhendra committed Oct 22, 2024
1 parent 5386540 commit f780ad5
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions mindmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import time
from streamlit_markmap import markmap
import json

# Set up OpenAI client
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
Expand All @@ -25,13 +26,16 @@ def generate_mindmap(query: str) -> str:
st.error(f"Error generating mindmap: {str(e)}")
return "# Error\n## Sorry, I couldn't generate a mindmap at this time."

def generate_analysis(mindmap_content: str) -> str:
def generate_analysis(mindmap_content: str, topic_data: list) -> str:
# Extract relevant information from topic_data
relevant_info = "\n".join([item['text'] for item in topic_data[:10]]) # Use first 10 items as context

try:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a medical expert specializing in USMLE Step 1 content. Provide a critical analysis report based on the given mindmap, expanding upon the topics to help USMLE Step 1 students understand this topic immediately."},
{"role": "user", "content": f"Based on the following mindmap, provide a critical analysis report for USMLE Step 1 students:\n\n{mindmap_content}"}
{"role": "system", "content": "You are a medical expert specializing in USMLE Step 1 content. Provide a critical analysis report based on the given mindmap and additional context, expanding upon the topics to help USMLE Step 1 students understand this topic immediately. Use the additional context to enrich your analysis with specific details and examples."},
{"role": "user", "content": f"Based on the following mindmap and additional context, provide a critical analysis report for USMLE Step 1 students:\n\nMindmap:\n{mindmap_content}\n\nAdditional Context:\n{relevant_info}"}
],
max_tokens=1500,
n=1,
Expand All @@ -44,14 +48,15 @@ def generate_analysis(mindmap_content: str) -> str:
return "Sorry, I couldn't generate an analysis at this time."

def display_mindmap(mindmap_content: str):
# Display the raw markdown content
# st.subheader("Markdown Content:")
# st.code(mindmap_content, language="markdown")

# Display the mindmap using markmap
st.subheader("Interactive Mindmap:")
markmap(mindmap_content)

def load_topic_data(topic: str) -> list:
file_path = os.path.join('data', f'{topic.lower()}_videos.json')
with open(file_path, 'r') as f:
return json.load(f)

def mindmap_tab_content():
st.header("Mindmap")

Expand All @@ -75,10 +80,14 @@ def mindmap_tab_content():
with st.expander("View Mindmap"):
display_mindmap(mindmap)

# Load topic data
topic = st.session_state.get('topic_selectbox', 'immunology') # Default to 'immunology' if not set
topic_data = load_topic_data(topic)

# Generate and display the analysis
st.subheader("Analysis")
with st.spinner("Generating analysis..."):
analysis = generate_analysis(mindmap)
analysis = generate_analysis(mindmap, topic_data)

with st.expander("View Analysis"):
st.markdown(analysis)
Expand Down

0 comments on commit f780ad5

Please sign in to comment.