sunbal7 commited on
Commit
163c417
·
verified ·
1 Parent(s): db0155e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -12,10 +12,10 @@ from reportlab.pdfgen import canvas
12
  import io
13
  from transformers import AutoModel, AutoTokenizer
14
 
15
- # Set page config as the very first Streamlit command
16
  st.set_page_config(page_title="🧠 Personality Prodigy", layout="wide", page_icon="🤖")
17
 
18
- # Initialize Groq client (Ensure API key is available in Streamlit secrets)
19
  if "GROQ_API_KEY" in st.secrets:
20
  groq_client = Groq(api_key=st.secrets["GROQ_API_KEY"])
21
  else:
@@ -30,11 +30,11 @@ try:
30
  except Exception as e:
31
  st.error(f"Error loading emotion classifier: {e}")
32
 
33
- # Big Five Personality Model using a valid, open source model
34
  try:
35
  big5_model = pipeline(
36
  "text-classification",
37
- model="pratik7/bigfive-personality", # Updated model identifier
38
  top_k=5
39
  )
40
  except Exception as e:
@@ -82,7 +82,7 @@ QUESTION_BANK = [
82
  def analyze_big5(text):
83
  """Analyze Big Five personality traits using the OCEAN model."""
84
  results = big5_model(text[:512])
85
- # Assuming labels are in a format like "BIGFIVE_<TRAIT>"
86
  return {result['label'].split("_")[-1].lower(): result['score'] for result in results}
87
 
88
  def get_dynamic_questions(responses):
@@ -99,7 +99,7 @@ def analyze_emotions(text):
99
  return personality_classifier(text[:512])
100
 
101
  def generate_quote(traits):
102
- """Generate personality-specific quote using Groq/Mistral."""
103
  prompt = f"""Create a motivational quote for someone with these traits:
104
  {traits}
105
  Make it inspirational, funny, and include an emoji."""
@@ -127,7 +127,7 @@ def generate_tips(traits):
127
  return tips[:10]
128
 
129
  def create_personality_report(responses):
130
- """Generate comprehensive personality analysis."""
131
  text = "\n".join(responses)
132
  big5_results = analyze_big5(text)
133
  return {
 
12
  import io
13
  from transformers import AutoModel, AutoTokenizer
14
 
15
+ # Set page configuration as the very first command
16
  st.set_page_config(page_title="🧠 Personality Prodigy", layout="wide", page_icon="🤖")
17
 
18
+ # Initialize Groq client (ensure API key is available in Streamlit secrets)
19
  if "GROQ_API_KEY" in st.secrets:
20
  groq_client = Groq(api_key=st.secrets["GROQ_API_KEY"])
21
  else:
 
30
  except Exception as e:
31
  st.error(f"Error loading emotion classifier: {e}")
32
 
33
+ # Big Five Personality Model using a publicly available model on Hugging Face
34
  try:
35
  big5_model = pipeline(
36
  "text-classification",
37
+ model="m3hrdadfi/bigfive-personality", # Updated model identifier
38
  top_k=5
39
  )
40
  except Exception as e:
 
82
  def analyze_big5(text):
83
  """Analyze Big Five personality traits using the OCEAN model."""
84
  results = big5_model(text[:512])
85
+ # Process the returned labels; adjust split logic if needed based on the model's output format
86
  return {result['label'].split("_")[-1].lower(): result['score'] for result in results}
87
 
88
  def get_dynamic_questions(responses):
 
99
  return personality_classifier(text[:512])
100
 
101
  def generate_quote(traits):
102
+ """Generate a personality-specific quote using Groq/Mistral."""
103
  prompt = f"""Create a motivational quote for someone with these traits:
104
  {traits}
105
  Make it inspirational, funny, and include an emoji."""
 
127
  return tips[:10]
128
 
129
  def create_personality_report(responses):
130
+ """Generate a comprehensive personality analysis."""
131
  text = "\n".join(responses)
132
  big5_results = analyze_big5(text)
133
  return {