ANON-STUDIOS-254 commited on
Commit
979381d
·
verified ·
1 Parent(s): a33f7f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -7,21 +7,21 @@ from huggingface_hub import InferenceClient
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
  # Set default values for model parameters and system message
10
- DEFAULT_MAX_TOKENS = 1000
11
- DEFAULT_TEMPERATURE = 0.8
12
  DEFAULT_TOP_P = 0.95
13
- DEFAULT_SYSTEM_MESSAGE = "You are an expert in environmental psychology. Provide expert recommendations addressing the client directly. Not like a letter though but like a professional report."
14
 
15
- def generate_recommendations(comfort, social_interaction, stressors, privacy, open_question, max_tokens=DEFAULT_MAX_TOKENS, temperature=DEFAULT_TEMPERATURE, top_p=DEFAULT_TOP_P, system_message=DEFAULT_SYSTEM_MESSAGE):
16
  # Construct the input message for the model with context
17
  message = (f"{system_message}\n"
18
- f"On a scale of 1-5, with 5 being the highest and 1 being the least ideal, the user rated the following:\n"
19
  f"Comfort and Well-being: {comfort}\n"
20
  f"Social Interaction: {social_interaction}\n"
21
  f"Environmental Stressors: {stressors}\n"
22
  f"Privacy and Personal Space: {privacy}\n"
23
  f"Open-ended Question: {open_question}\n"
24
- f"Please provide personalized recommendations addressing the user directly.")
25
 
26
  # Generate recommendations using the Hugging Face model
27
  response = client.chat_completion(
@@ -36,7 +36,7 @@ def generate_recommendations(comfort, social_interaction, stressors, privacy, op
36
  recommendations = recommendations.replace("You should", "I recommend that you")
37
  return recommendations
38
 
39
- def analyze_environmental_concerns(comfort, social_interaction, stressors, privacy, open_question):
40
  # Generate a bar graph for the input scores with Ukiyo-e theme colors
41
  fig, ax = plt.subplots(figsize=(10, 6)) # Increased size for better visibility
42
  categories = ["Comfort and Well-being", "Social Interaction", "Environmental Stressors", "Privacy and Personal Space"]
@@ -46,7 +46,7 @@ def analyze_environmental_concerns(comfort, social_interaction, stressors, priva
46
 
47
  # Improve graph display
48
  ax.set_ylabel('Score', fontsize=14, color='#333333')
49
- ax.set_title('Environmental Psychology Concerns', fontsize=16, color='#333333')
50
  ax.yaxis.set_major_locator(MaxNLocator(integer=True))
51
  ax.tick_params(axis='y', colors='#333333')
52
  ax.tick_params(axis='x', colors='#333333')
@@ -57,7 +57,7 @@ def analyze_environmental_concerns(comfort, social_interaction, stressors, priva
57
  ax.text(bar.get_x() + bar.get_width()/2, yval, int(yval), va='bottom', ha='center', color='black', fontsize=12)
58
 
59
  # Generate recommendations using the model
60
- recommendations = generate_recommendations(comfort, social_interaction, stressors, privacy, open_question)
61
 
62
  return fig, recommendations
63
 
@@ -100,7 +100,8 @@ inputs = [
100
  gr.Slider(minimum=1, maximum=5, step=1, label="How would you rate Social Interaction?"),
101
  gr.Slider(minimum=1, maximum=5, step=1, label="How would you rate Environmental Stressors?"),
102
  gr.Slider(minimum=1, maximum=5, step=1, label="How would you rate Privacy and Personal Space?"),
103
- gr.Textbox(placeholder="Describe any additional concerns or suggestions you have.", label="Open-ended Question", lines=3)
 
104
  ]
105
 
106
  outputs = [
 
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
  # Set default values for model parameters and system message
10
+ DEFAULT_MAX_TOKENS = 512
11
+ DEFAULT_TEMPERATURE = 0.7
12
  DEFAULT_TOP_P = 0.95
13
+ DEFAULT_SYSTEM_MESSAGE = "You are an expert in environmental psychology. Provide expert recommendations addressing the user directly."
14
 
15
+ def generate_recommendations(comfort, social_interaction, stressors, privacy, open_question, alias, max_tokens=DEFAULT_MAX_TOKENS, temperature=DEFAULT_TEMPERATURE, top_p=DEFAULT_TOP_P, system_message=DEFAULT_SYSTEM_MESSAGE):
16
  # Construct the input message for the model with context
17
  message = (f"{system_message}\n"
18
+ f"On a scale of 1-5, with 5 being the highest and 1 being the least ideal, {alias} rated the following:\n"
19
  f"Comfort and Well-being: {comfort}\n"
20
  f"Social Interaction: {social_interaction}\n"
21
  f"Environmental Stressors: {stressors}\n"
22
  f"Privacy and Personal Space: {privacy}\n"
23
  f"Open-ended Question: {open_question}\n"
24
+ f"Please provide personalized recommendations for {alias}, addressing them directly.")
25
 
26
  # Generate recommendations using the Hugging Face model
27
  response = client.chat_completion(
 
36
  recommendations = recommendations.replace("You should", "I recommend that you")
37
  return recommendations
38
 
39
+ def analyze_environmental_concerns(comfort, social_interaction, stressors, privacy, open_question, alias):
40
  # Generate a bar graph for the input scores with Ukiyo-e theme colors
41
  fig, ax = plt.subplots(figsize=(10, 6)) # Increased size for better visibility
42
  categories = ["Comfort and Well-being", "Social Interaction", "Environmental Stressors", "Privacy and Personal Space"]
 
46
 
47
  # Improve graph display
48
  ax.set_ylabel('Score', fontsize=14, color='#333333')
49
+ ax.set_title(f'Environmental Psychology Concerns for {alias}', fontsize=16, color='#333333')
50
  ax.yaxis.set_major_locator(MaxNLocator(integer=True))
51
  ax.tick_params(axis='y', colors='#333333')
52
  ax.tick_params(axis='x', colors='#333333')
 
57
  ax.text(bar.get_x() + bar.get_width()/2, yval, int(yval), va='bottom', ha='center', color='black', fontsize=12)
58
 
59
  # Generate recommendations using the model
60
+ recommendations = generate_recommendations(comfort, social_interaction, stressors, privacy, open_question, alias)
61
 
62
  return fig, recommendations
63
 
 
100
  gr.Slider(minimum=1, maximum=5, step=1, label="How would you rate Social Interaction?"),
101
  gr.Slider(minimum=1, maximum=5, step=1, label="How would you rate Environmental Stressors?"),
102
  gr.Slider(minimum=1, maximum=5, step=1, label="How would you rate Privacy and Personal Space?"),
103
+ gr.Textbox(placeholder="Describe any additional concerns or suggestions you have.", label="Open-ended Question", lines=3),
104
+ gr.Textbox(placeholder="Enter a single-word alias (e.g., anon).", label="Client Alias", lines=1) # New input for alias
105
  ]
106
 
107
  outputs = [