Spaces:
Running
Running
Yufan_Zhou
commited on
Commit
·
83fafff
1
Parent(s):
5b5571e
Fix user input handling and improve UI readability
Browse files- .gitattributes +0 -3
- app.py +29 -19
- generate_user_profile_final/code/web_api_bridge.py +32 -8
.gitattributes
CHANGED
|
@@ -19,9 +19,6 @@
|
|
| 19 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
# Exception: allow these specific pkl files to be committed normally
|
| 23 |
-
generate_user_profile_final/data/attribute_embeddings.pkl -filter -diff -merge
|
| 24 |
-
generate_user_profile_final/data/attributes_merged_embeddings.pkl -filter -diff -merge
|
| 25 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 26 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 27 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 19 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
*.pkl filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
| 22 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -32,21 +32,26 @@ def generate_persona(age, gender, occupation, city, country, custom_values, cust
|
|
| 32 |
return "❌ Error: OpenAI API key not set. Please add OPENAI_API_KEY in Hugging Face Space settings."
|
| 33 |
|
| 34 |
# Build input data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
input_data = {
|
| 36 |
"basic_info": {
|
| 37 |
-
"age": age if age else None,
|
| 38 |
-
"gender": gender if gender else None,
|
| 39 |
-
"occupation": {"status": occupation} if occupation else {},
|
| 40 |
-
"location":
|
| 41 |
-
"city": city,
|
| 42 |
-
"country": country
|
| 43 |
-
} if city and country else {}
|
| 44 |
},
|
| 45 |
"custom_values": {
|
| 46 |
-
"personal_values": custom_values if custom_values else None,
|
| 47 |
-
"life_attitude": custom_life_attitude if custom_life_attitude else None,
|
| 48 |
-
"life_story": life_story if life_story else None,
|
| 49 |
-
"interests_hobbies": interests_hobbies if interests_hobbies else None
|
| 50 |
}
|
| 51 |
}
|
| 52 |
|
|
@@ -104,9 +109,7 @@ div, section, form, .app, .contain, .wrap {
|
|
| 104 |
|
| 105 |
.header-text {
|
| 106 |
text-align: center;
|
| 107 |
-
|
| 108 |
-
-webkit-background-clip: text;
|
| 109 |
-
-webkit-text-fill-color: transparent;
|
| 110 |
font-size: 3.2em !important;
|
| 111 |
font-weight: bold;
|
| 112 |
margin-bottom: 0.2em;
|
|
@@ -114,7 +117,7 @@ div, section, form, .app, .contain, .wrap {
|
|
| 114 |
|
| 115 |
.subtitle-text {
|
| 116 |
text-align: center;
|
| 117 |
-
color: #
|
| 118 |
font-size: 1.5em;
|
| 119 |
margin-bottom: 0.8em;
|
| 120 |
}
|
|
@@ -200,11 +203,11 @@ h3 .section-header {
|
|
| 200 |
|
| 201 |
/* Adjust input field spacing */
|
| 202 |
.input-column label {
|
| 203 |
-
margin-bottom:
|
| 204 |
-
margin-top:
|
| 205 |
font-size: 1.4em !important;
|
| 206 |
-
color: #
|
| 207 |
-
font-weight:
|
| 208 |
display: block !important;
|
| 209 |
padding-top: 0px !important;
|
| 210 |
}
|
|
@@ -298,6 +301,13 @@ div[class*="gr-row"],
|
|
| 298 |
padding: 0 !important;
|
| 299 |
gap: 12px !important;
|
| 300 |
margin: 0 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
}
|
| 302 |
|
| 303 |
/* Remove padding from form containers */
|
|
|
|
| 32 |
return "❌ Error: OpenAI API key not set. Please add OPENAI_API_KEY in Hugging Face Space settings."
|
| 33 |
|
| 34 |
# Build input data
|
| 35 |
+
# Build location dict - only include if both city and country are provided
|
| 36 |
+
location_dict = {}
|
| 37 |
+
if city and city.strip() and country and country.strip():
|
| 38 |
+
location_dict = {
|
| 39 |
+
"city": city.strip(),
|
| 40 |
+
"country": country.strip()
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
input_data = {
|
| 44 |
"basic_info": {
|
| 45 |
+
"age": int(age) if age else None,
|
| 46 |
+
"gender": gender.strip() if gender and gender.strip() else None,
|
| 47 |
+
"occupation": {"status": occupation.strip()} if occupation and occupation.strip() else {},
|
| 48 |
+
"location": location_dict
|
|
|
|
|
|
|
|
|
|
| 49 |
},
|
| 50 |
"custom_values": {
|
| 51 |
+
"personal_values": custom_values.strip() if custom_values and custom_values.strip() else None,
|
| 52 |
+
"life_attitude": custom_life_attitude.strip() if custom_life_attitude and custom_life_attitude.strip() else None,
|
| 53 |
+
"life_story": life_story.strip() if life_story and life_story.strip() else None,
|
| 54 |
+
"interests_hobbies": interests_hobbies.strip() if interests_hobbies and interests_hobbies.strip() else None
|
| 55 |
}
|
| 56 |
}
|
| 57 |
|
|
|
|
| 109 |
|
| 110 |
.header-text {
|
| 111 |
text-align: center;
|
| 112 |
+
color: #222 !important;
|
|
|
|
|
|
|
| 113 |
font-size: 3.2em !important;
|
| 114 |
font-weight: bold;
|
| 115 |
margin-bottom: 0.2em;
|
|
|
|
| 117 |
|
| 118 |
.subtitle-text {
|
| 119 |
text-align: center;
|
| 120 |
+
color: #333;
|
| 121 |
font-size: 1.5em;
|
| 122 |
margin-bottom: 0.8em;
|
| 123 |
}
|
|
|
|
| 203 |
|
| 204 |
/* Adjust input field spacing */
|
| 205 |
.input-column label {
|
| 206 |
+
margin-bottom: 4px !important;
|
| 207 |
+
margin-top: 8px !important;
|
| 208 |
font-size: 1.4em !important;
|
| 209 |
+
color: #222 !important;
|
| 210 |
+
font-weight: 600 !important;
|
| 211 |
display: block !important;
|
| 212 |
padding-top: 0px !important;
|
| 213 |
}
|
|
|
|
| 301 |
padding: 0 !important;
|
| 302 |
gap: 12px !important;
|
| 303 |
margin: 0 !important;
|
| 304 |
+
align-items: flex-start !important;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
/* Ensure columns in rows align properly */
|
| 308 |
+
.input-column .gr-row > div {
|
| 309 |
+
flex: 1 1 0 !important;
|
| 310 |
+
min-width: 0 !important;
|
| 311 |
}
|
| 312 |
|
| 313 |
/* Remove padding from form containers */
|
generate_user_profile_final/code/web_api_bridge.py
CHANGED
|
@@ -67,22 +67,34 @@ def generate_profile_from_input(input_data: Dict[str, Any], attribute_count: int
|
|
| 67 |
# Use provided basic information or generate new basic information
|
| 68 |
age = basic_info.get('age')
|
| 69 |
if not age:
|
|
|
|
| 70 |
age_info = generate_age_info()
|
| 71 |
age = age_info['age']
|
|
|
|
|
|
|
| 72 |
|
| 73 |
gender = basic_info.get('gender')
|
| 74 |
if not gender:
|
|
|
|
| 75 |
gender = generate_gender()
|
|
|
|
|
|
|
| 76 |
|
| 77 |
occupation_info = basic_info.get('occupation', {})
|
| 78 |
occupation = occupation_info.get('status')
|
| 79 |
if not occupation:
|
|
|
|
| 80 |
career_info = generate_career_info(age)
|
| 81 |
occupation = career_info['status']
|
|
|
|
|
|
|
| 82 |
|
| 83 |
location_info = basic_info.get('location', {})
|
| 84 |
-
if not location_info or not location_info.get('
|
|
|
|
| 85 |
location_info = generate_location()
|
|
|
|
|
|
|
| 86 |
|
| 87 |
# Use custom personal values if provided, otherwise generate them
|
| 88 |
custom_personal_values = custom_values.get('personal_values')
|
|
@@ -105,13 +117,25 @@ def generate_profile_from_input(input_data: Dict[str, Any], attribute_count: int
|
|
| 105 |
print("Generating life attitude...")
|
| 106 |
life_attitude = generate_life_attitude(age, gender, occupation, location_info, values_orientation)
|
| 107 |
|
| 108 |
-
#
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
# Build base profile structure that will be saved to user_profile.json
|
| 117 |
# This needs to be saved before calling generate_single_profile
|
|
|
|
| 67 |
# Use provided basic information or generate new basic information
|
| 68 |
age = basic_info.get('age')
|
| 69 |
if not age:
|
| 70 |
+
print("No age provided, generating random age...")
|
| 71 |
age_info = generate_age_info()
|
| 72 |
age = age_info['age']
|
| 73 |
+
else:
|
| 74 |
+
print(f"Using provided age: {age}")
|
| 75 |
|
| 76 |
gender = basic_info.get('gender')
|
| 77 |
if not gender:
|
| 78 |
+
print("No gender provided, generating random gender...")
|
| 79 |
gender = generate_gender()
|
| 80 |
+
else:
|
| 81 |
+
print(f"Using provided gender: {gender}")
|
| 82 |
|
| 83 |
occupation_info = basic_info.get('occupation', {})
|
| 84 |
occupation = occupation_info.get('status')
|
| 85 |
if not occupation:
|
| 86 |
+
print("No occupation provided, generating random occupation...")
|
| 87 |
career_info = generate_career_info(age)
|
| 88 |
occupation = career_info['status']
|
| 89 |
+
else:
|
| 90 |
+
print(f"Using provided occupation: {occupation}")
|
| 91 |
|
| 92 |
location_info = basic_info.get('location', {})
|
| 93 |
+
if not location_info.get('city') or not location_info.get('country'):
|
| 94 |
+
print("No complete location provided, generating random location...")
|
| 95 |
location_info = generate_location()
|
| 96 |
+
else:
|
| 97 |
+
print(f"Using provided location: {location_info.get('city')}, {location_info.get('country')}")
|
| 98 |
|
| 99 |
# Use custom personal values if provided, otherwise generate them
|
| 100 |
custom_personal_values = custom_values.get('personal_values')
|
|
|
|
| 117 |
print("Generating life attitude...")
|
| 118 |
life_attitude = generate_life_attitude(age, gender, occupation, location_info, values_orientation)
|
| 119 |
|
| 120 |
+
# Use custom life story if provided, otherwise generate it
|
| 121 |
+
custom_life_story = custom_values.get('life_story')
|
| 122 |
+
if custom_life_story and custom_life_story.strip():
|
| 123 |
+
print("Using provided life story...")
|
| 124 |
+
personal_story = {"personal_story": custom_life_story.strip()}
|
| 125 |
+
else:
|
| 126 |
+
print("Generating personal story...")
|
| 127 |
+
personal_story = generate_personal_story(age, gender, occupation, location_info, values_orientation, life_attitude)
|
| 128 |
+
|
| 129 |
+
# Use custom interests/hobbies if provided, otherwise generate them
|
| 130 |
+
custom_interests = custom_values.get('interests_hobbies')
|
| 131 |
+
if custom_interests and custom_interests.strip():
|
| 132 |
+
print("Using provided interests and hobbies...")
|
| 133 |
+
# Split by comma and clean up
|
| 134 |
+
interests_list = [i.strip() for i in custom_interests.split(',') if i.strip()]
|
| 135 |
+
interests_and_hobbies = {"interests": interests_list}
|
| 136 |
+
else:
|
| 137 |
+
print("Generating interests and hobbies...")
|
| 138 |
+
interests_and_hobbies = generate_interests_and_hobbies(personal_story)
|
| 139 |
|
| 140 |
# Build base profile structure that will be saved to user_profile.json
|
| 141 |
# This needs to be saved before calling generate_single_profile
|