johnpaulbin commited on
Commit
752889a
·
verified ·
1 Parent(s): 2a34d99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -22
app.py CHANGED
@@ -72,28 +72,23 @@ traits = {
72
  }
73
  }
74
 
75
- # Define the scoring function
76
  def compute_trait_scores(*args):
77
  responses = {}
78
  for i, item in enumerate(items):
79
  key = item['key']
80
- response = int(args[i])
81
- responses[key] = response
82
 
83
  trait_scores = {}
84
  for trait, trait_data in traits.items():
85
  positive_sum = 0
86
  negative_sum = 0
87
  for item_key in trait_data['positive']:
88
- try:
89
- positive_sum += responses[item_key]
90
- except KeyError:
91
- print(f"Warning: Response for {item_key} not found.") #Handle missing keys gracefully.
92
  for item_key in trait_data['negative']:
93
- try:
94
- negative_sum += 6 - responses[item_key]
95
- except KeyError:
96
- print(f"Warning: Response for {item_key} not found.") #Handle missing keys gracefully.
97
 
98
  trait_scores[trait] = positive_sum + negative_sum
99
 
@@ -106,18 +101,8 @@ for item in items:
106
  input_component = gr.Radio(
107
  label=question,
108
  choices=['1 (Disagree a lot)', '2', '3', '4', '5 (Agree a lot)'],
109
- type='value',
110
- required=True
111
  )
112
  inputs.append(input_component)
113
 
114
- iface = gr.Interface(
115
- fn=compute_trait_scores,
116
- inputs=inputs,
117
- outputs=gr.JSON(label="Your Big Five Personality Scores"),
118
- title='Big Five Personality Test',
119
- description='Answer the following questions to see your Big Five personality trait scores.',
120
- allow_flagging='never'
121
- )
122
-
123
  iface.launch()
 
72
  }
73
  }
74
 
 
75
  def compute_trait_scores(*args):
76
  responses = {}
77
  for i, item in enumerate(items):
78
  key = item['key']
79
+ response = args[i] # Handle potential None values
80
+ responses[key] = response if response is not None else 3 # Default to neutral (3) if no response
81
 
82
  trait_scores = {}
83
  for trait, trait_data in traits.items():
84
  positive_sum = 0
85
  negative_sum = 0
86
  for item_key in trait_data['positive']:
87
+ response = responses.get(item_key, 3) # Get response or default to 3
88
+ positive_sum += response
 
 
89
  for item_key in trait_data['negative']:
90
+ response = responses.get(item_key, 3) # Get response or default to 3
91
+ negative_sum += 6 - response
 
 
92
 
93
  trait_scores[trait] = positive_sum + negative_sum
94
 
 
101
  input_component = gr.Radio(
102
  label=question,
103
  choices=['1 (Disagree a lot)', '2', '3', '4', '5 (Agree a lot)'],
104
+ type='value' # removed required=True
 
105
  )
106
  inputs.append(input_component)
107
 
 
 
 
 
 
 
 
 
 
108
  iface.launch()