import pandas as pd import streamlit as st import json from utils import client def analyze_crossover_potential(thread_id, additional_context=None): if additional_context: client.beta.threads.messages.create( thread_id=thread_id, role="user", content=json.dumps(additional_context) ) run = client.beta.threads.runs.create( thread_id=thread_id, assistant_id="asst_Kz39dY89bAF83rFCBhwTmvul" ) while run.status in ['queued', 'in_progress', 'cancelling']: run = client.beta.threads.runs.retrieve( thread_id=thread_id, run_id=run.id ) if run.status == 'completed': messages = client.beta.threads.messages.list(thread_id=thread_id) analysis = next((msg.content[0].text.value for msg in reversed(list(messages)) if msg.role == "assistant"), "") return analysis else: return f"Error: Run status is {run.status}" def process_crossover_potential(analysis): try: df = pd.json_normalize(json.loads(analysis)) st.dataframe(df) st.bar_chart(df.set_index('synopsis')['crossover_potential']) except Exception as e: st.error(f"Error processing data for Crossover Potential: {e}") st.write("Please check the structure of the JSON data:") st.json(analysis)