shukdevdatta123 commited on
Commit
e54503a
·
verified ·
1 Parent(s): 5263b1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -37
app.py CHANGED
@@ -2,8 +2,6 @@ import streamlit as st
2
  import openai
3
  from dotenv import load_dotenv
4
  import os
5
- from PIL import Image, ImageDraw, ImageFont
6
- import io
7
 
8
  # Load the OpenAI API Key
9
  api_key = st.text_input('Enter your OpenAI API Key', type="password")
@@ -72,25 +70,6 @@ def classic_mbti_weighted(responses):
72
  mbti_type += trait2
73
  return mbti_type
74
 
75
- # Function to create an image from text
76
- def create_image_from_text(text):
77
- # Create an empty image with white background
78
- img = Image.new('RGB', (600, 400), color='white')
79
- draw = ImageDraw.Draw(img)
80
-
81
- # Load font (You can customize font and size)
82
- font = ImageFont.load_default()
83
-
84
- # Draw the text on the image
85
- draw.text((10, 10), text, fill='black', font=font)
86
-
87
- # Save to a buffer
88
- buf = io.BytesIO()
89
- img.save(buf, format="PNG")
90
- buf.seek(0)
91
-
92
- return buf
93
-
94
  # Streamlit component to display the quiz and handle responses
95
  def show_mbti_quiz():
96
  st.title('FlexTemp Personality Test')
@@ -115,22 +94,27 @@ def show_mbti_quiz():
115
  if st.button("Generate Personality Trait Information"):
116
  st.subheader("Your MBTI Personality Type:")
117
  mbti_type_classic = classic_mbti_weighted(responses)
118
- result_text = f"Your MBTI type based on weighted answers: {mbti_type_classic}"
119
-
120
- # Display result text
121
- st.write(result_text)
122
-
123
- # Create an image of the result
124
- image_buf = create_image_from_text(result_text)
125
-
126
- # Display the generated image in Streamlit
127
- st.image(image_buf)
128
-
129
- # Optionally, save the image to disk
130
- with open("personality_type_image.png", "wb") as f:
131
- f.write(image_buf.read())
132
- st.success("Your result image has been saved as 'personality_type_image.png'.")
133
-
 
 
 
 
 
134
  else:
135
  st.warning("Please answer all the questions!")
136
 
 
2
  import openai
3
  from dotenv import load_dotenv
4
  import os
 
 
5
 
6
  # Load the OpenAI API Key
7
  api_key = st.text_input('Enter your OpenAI API Key', type="password")
 
70
  mbti_type += trait2
71
  return mbti_type
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  # Streamlit component to display the quiz and handle responses
74
  def show_mbti_quiz():
75
  st.title('FlexTemp Personality Test')
 
94
  if st.button("Generate Personality Trait Information"):
95
  st.subheader("Your MBTI Personality Type:")
96
  mbti_type_classic = classic_mbti_weighted(responses)
97
+ st.write(f"Your MBTI type based on weighted answers: {mbti_type_classic}")
98
+
99
+ # You can add LLM-based prediction if needed here (example OpenAI-based model)
100
+ if api_key:
101
+ # Run the LLM (GPT-4, for example) model to generate a personality type.
102
+ prompt = f"""
103
+ Determine a person's personality type based on their answers to the following Myers-Briggs Type Indicator (MBTI) questions:
104
+ The person has answered the following questions:
105
+ {', '.join([f"{question['text']} {response}" for question, response in zip(questions, responses)])}
106
+ What is the MBTI personality type based on these answers?
107
+ """
108
+ try:
109
+ response = openai.ChatCompletion.create(
110
+ model="gpt-4o",
111
+ messages=[{"role": "system", "content": "You are a helpful assistant."},
112
+ {"role": "user", "content": prompt}]
113
+ )
114
+ mbti_type_llm = response['choices'][0]['message']['content']
115
+ st.write(f"Your MBTI type according to AI: {mbti_type_llm}")
116
+ except Exception as e:
117
+ st.error(f"Error occurred: {e}")
118
  else:
119
  st.warning("Please answer all the questions!")
120