AUXteam commited on
Commit
e633494
·
verified ·
1 Parent(s): c574339

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +20 -9
  2. config.ini +1 -1
app.py CHANGED
@@ -16,28 +16,28 @@ REMOTE_BACKEND = "https://auxteam-tiny-factory.hf.space"
16
 
17
  def generate_personas(business_description, customer_profile, num_personas, api_key=None):
18
  if api_key:
19
- os.environ["BLABLADOR_API_KEY"] = api_key
20
  os.environ["OPENAI_API_KEY"] = api_key
21
 
22
  import json
 
23
  from gradio_client import Client
24
  import openai
 
25
 
26
  client = openai.OpenAI()
27
  dp_client = Client("THzva/deeppersona-experience")
28
 
29
  personas = []
30
 
31
- for _ in range(int(num_personas)):
32
- # 1. Generate initial parameters for the 200 API call
33
  prompt_1 = f"""
34
  Given the following business description and customer profile:
35
  Business: {business_description}
36
  Customer: {customer_profile}
37
 
38
- Generate realistic parameters for a persona that fits this profile. Return ONLY a valid JSON object with these EXACT keys:
39
  "Age" (number), "Gender" (string), "Occupation" (string), "City" (string), "Country" (string), "Personal Values" (string), "Life Attitude" (string), "Life Story" (string), "Interests and Hobbies" (string).
40
- Keep the string fields concise (1-2 sentences).
41
  """
42
  response_1 = client.chat.completions.create(
43
  model="gpt-4o-mini",
@@ -96,8 +96,8 @@ Extract and enhance specific details to create an updated set of parameters. Ret
96
  Based on this final generated persona output:
97
  {result_400}
98
 
99
- Extract the persona details into a structured format. Return ONLY a valid JSON object with these EXACT keys:
100
- "name" (string, make one up if not found), "age" (number), "nationality" (string), "country_of_residence" (string), "occupation" (string), "residence" (string).
101
  """
102
  response_3 = client.chat.completions.create(
103
  model="gpt-4o-mini",
@@ -105,10 +105,21 @@ Extract the persona details into a structured format. Return ONLY a valid JSON o
105
  response_format={"type": "json_object"}
106
  )
107
  final_persona = json.loads(response_3.choices[0].message.content)
108
- final_persona["full_profile_text"] = result_400
109
- personas.append(final_persona)
 
 
 
 
 
 
 
 
 
110
 
111
  return personas
 
 
112
  def start_simulation(name, content_text, format_type, persona_count, network_type):
113
  config = SimulationConfig(name=name, persona_count=int(persona_count), network_type=network_type)
114
  sim = simulation_manager.create_simulation(config)
 
16
 
17
  def generate_personas(business_description, customer_profile, num_personas, api_key=None):
18
  if api_key:
 
19
  os.environ["OPENAI_API_KEY"] = api_key
20
 
21
  import json
22
+ import random
23
  from gradio_client import Client
24
  import openai
25
+ from tinytroupe.agent.tiny_person import TinyPerson
26
 
27
  client = openai.OpenAI()
28
  dp_client = Client("THzva/deeppersona-experience")
29
 
30
  personas = []
31
 
32
+ for i in range(int(num_personas)):
33
+ # 1. Generate initial parameters for the 200 API call using OpenAI compatible endpoint
34
  prompt_1 = f"""
35
  Given the following business description and customer profile:
36
  Business: {business_description}
37
  Customer: {customer_profile}
38
 
39
+ Generate realistic parameters for a persona. Return ONLY a valid JSON object with these EXACT keys:
40
  "Age" (number), "Gender" (string), "Occupation" (string), "City" (string), "Country" (string), "Personal Values" (string), "Life Attitude" (string), "Life Story" (string), "Interests and Hobbies" (string).
 
41
  """
42
  response_1 = client.chat.completions.create(
43
  model="gpt-4o-mini",
 
96
  Based on this final generated persona output:
97
  {result_400}
98
 
99
+ Extract the persona details. Return ONLY a valid JSON object with these EXACT keys:
100
+ "name" (string, make one up if not found), "age" (number), "nationality" (string), "country_of_residence" (string), "occupation" (string).
101
  """
102
  response_3 = client.chat.completions.create(
103
  model="gpt-4o-mini",
 
105
  response_format={"type": "json_object"}
106
  )
107
  final_persona = json.loads(response_3.choices[0].message.content)
108
+
109
+ # Transform output into a tinytroupe persona profile
110
+ tp = TinyPerson(name=final_persona.get("name", f"Persona {i+1}"))
111
+ tp._persona["age"] = final_persona.get("age", 30)
112
+ tp._persona["nationality"] = final_persona.get("nationality", "Unknown")
113
+ tp._persona["country_of_residence"] = final_persona.get("country_of_residence", "Unknown")
114
+ tp._persona["residence"] = final_persona.get("country_of_residence", "Unknown")
115
+ tp._persona["occupation"] = final_persona.get("occupation", "Professional")
116
+ tp._persona["full_profile_text"] = result_400
117
+
118
+ personas.append(tp._persona)
119
 
120
  return personas
121
+
122
+
123
  def start_simulation(name, content_text, format_type, persona_count, network_type):
124
  config = SimulationConfig(name=name, persona_count=int(persona_count), network_type=network_type)
125
  sim = simulation_manager.create_simulation(config)
config.ini CHANGED
@@ -1,5 +1,5 @@
1
  [OpenAI]
2
- API_TYPE=helmholtz-blablador
3
  MODEL=alias-fast
4
  REASONING_MODEL=alias-fast
5
  FALLBACK_MODEL_LARGE=alias-large
 
1
  [OpenAI]
2
+ API_TYPE=openai
3
  MODEL=alias-fast
4
  REASONING_MODEL=alias-fast
5
  FALLBACK_MODEL_LARGE=alias-large