ANON-STUDIOS-254 commited on
Commit
0abe49a
·
verified ·
1 Parent(s): 4bfa263

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import matplotlib.pyplot as plt
 
3
  from huggingface_hub import InferenceClient
4
 
5
  # Initialize Hugging Face Inference Client
@@ -11,7 +12,7 @@ DEFAULT_TEMPERATURE = 0.7
11
  DEFAULT_TOP_P = 0.95
12
  DEFAULT_SYSTEM_MESSAGE = "You are an expert in environmental psychology. Provide expert recommendations."
13
 
14
- def generate_recommendations(comfort, social_interaction, stressors, privacy, max_tokens=DEFAULT_MAX_TOKENS, temperature=DEFAULT_TEMPERATURE, top_p=DEFAULT_TOP_P, system_message=DEFAULT_SYSTEM_MESSAGE):
15
  # Construct the input message for the model with context
16
  message = (f"{system_message}\n"
17
  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,6 +20,7 @@ def generate_recommendations(comfort, social_interaction, stressors, privacy, ma
19
  f"Social Interaction: {social_interaction}\n"
20
  f"Environmental Stressors: {stressors}\n"
21
  f"Privacy and Personal Space: {privacy}\n"
 
22
  f"Provide recommendations for improving the environment based on these ratings.")
23
 
24
  # Generate recommendations using the Hugging Face model
@@ -32,26 +34,36 @@ def generate_recommendations(comfort, social_interaction, stressors, privacy, ma
32
  recommendations = response.choices[0].message['content']
33
  return recommendations
34
 
35
- def analyze_environmental_concerns(comfort, social_interaction, stressors, privacy):
36
- # Generate a bar graph for the input scores
37
  fig, ax = plt.subplots()
38
  categories = ["Comfort and Well-being", "Social Interaction", "Environmental Stressors", "Privacy and Personal Space"]
39
  values = [comfort, social_interaction, stressors, privacy]
40
- ax.bar(categories, values, color=['blue', 'orange', 'green', 'red'])
 
 
 
41
  ax.set_ylabel('Score')
42
  ax.set_title('Environmental Psychology Concerns')
 
 
 
 
 
 
43
 
44
  # Generate recommendations using the model
45
- recommendations = generate_recommendations(comfort, social_interaction, stressors, privacy)
46
 
47
  return fig, recommendations
48
 
49
- # Create the Gradio interface without exposing internal parameters to the user
50
  inputs = [
51
- gr.Slider(minimum=1, maximum=5, step=1, label="Comfort and Well-being"),
52
- gr.Slider(minimum=1, maximum=5, step=1, label="Social Interaction"),
53
- gr.Slider(minimum=1, maximum=5, step=1, label="Environmental Stressors"),
54
- gr.Slider(minimum=1, maximum=5, step=1, label="Privacy and Personal Space"),
 
55
  ]
56
 
57
  outputs = [
@@ -64,5 +76,6 @@ gr.Interface(
64
  inputs=inputs,
65
  outputs=outputs,
66
  title="Mazingira: Environmental Psychology Concerns Analyzer",
67
- description="Input your environmental psychology concerns to receive personalized recommendations and a visual graph."
 
68
  ).launch()
 
1
  import gradio as gr
2
  import matplotlib.pyplot as plt
3
+ from matplotlib.ticker import MaxNLocator
4
  from huggingface_hub import InferenceClient
5
 
6
  # Initialize Hugging Face Inference Client
 
12
  DEFAULT_TOP_P = 0.95
13
  DEFAULT_SYSTEM_MESSAGE = "You are an expert in environmental psychology. Provide expert recommendations."
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"
 
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"Provide recommendations for improving the environment based on these ratings.")
25
 
26
  # Generate recommendations using the Hugging Face model
 
34
  recommendations = response.choices[0].message['content']
35
  return recommendations
36
 
37
+ def analyze_environmental_concerns(comfort, social_interaction, stressors, privacy, open_question):
38
+ # Generate a bar graph for the input scores with Ukiyo-e theme colors
39
  fig, ax = plt.subplots()
40
  categories = ["Comfort and Well-being", "Social Interaction", "Environmental Stressors", "Privacy and Personal Space"]
41
  values = [comfort, social_interaction, stressors, privacy]
42
+
43
+ bars = ax.bar(categories, values, color=['#F08080', '#90EE90', '#000000', '#FFD700']) # Light red, light green, black, gold
44
+
45
+ # Improve graph display
46
  ax.set_ylabel('Score')
47
  ax.set_title('Environmental Psychology Concerns')
48
+ ax.yaxis.set_major_locator(MaxNLocator(integer=True))
49
+
50
+ # Add value labels on the bars
51
+ for bar in bars:
52
+ yval = bar.get_height()
53
+ ax.text(bar.get_x() + bar.get_width()/2, yval, int(yval), va='bottom', ha='center', color='black', fontsize=10)
54
 
55
  # Generate recommendations using the model
56
+ recommendations = generate_recommendations(comfort, social_interaction, stressors, privacy, open_question)
57
 
58
  return fig, recommendations
59
 
60
+ # Create the Gradio interface with Ukiyo-e theme
61
  inputs = [
62
+ gr.Slider(minimum=1, maximum=5, step=1, label="How would you rate Comfort and Well-being?"),
63
+ gr.Slider(minimum=1, maximum=5, step=1, label="How would you rate Social Interaction?"),
64
+ gr.Slider(minimum=1, maximum=5, step=1, label="How would you rate Environmental Stressors?"),
65
+ gr.Slider(minimum=1, maximum=5, step=1, label="How would you rate Privacy and Personal Space?"),
66
+ gr.Textbox(placeholder="Describe any additional concerns or suggestions you have.", label="Open-ended Question", lines=3)
67
  ]
68
 
69
  outputs = [
 
76
  inputs=inputs,
77
  outputs=outputs,
78
  title="Mazingira: Environmental Psychology Concerns Analyzer",
79
+ description="Input your environmental psychology concerns to receive personalized recommendations and a visual graph.",
80
+ theme="default" # Use default theme as Gradio doesn't support custom themes directly
81
  ).launch()