jackmedda commited on
Commit
a3892df
·
1 Parent(s): bafa006

Fix explanations

Browse files
html_items.py CHANGED
@@ -60,7 +60,7 @@ def create_poi_html(poi: dict, user_id: str) -> str:
60
  """
61
  html += f""" </tbody>
62
  </table>
63
- <div style="margin: 15px 0; padding: 10px; background-color: #3a3a3a; color: white; border-left: 5px solid #7FB77E; border-radius: 5px;" --explanation_type="{poi["explanation_type"]}">
64
  <h3>Spiegazione della raccomandazione: ti suggeriamo questo luogo perché ...</h3>
65
  <p>{poi["explanation"]}</p>
66
  </div>
 
60
  """
61
  html += f""" </tbody>
62
  </table>
63
+ <div style="margin: 15px 0; padding: 10px; background-color: #3a3a3a; color: white; border-left: 5px solid #7FB77E; border-radius: 5px;" --explanation_type="{poi.get("explanation_type", -1)}">
64
  <h3>Spiegazione della raccomandazione: ti suggeriamo questo luogo perché ...</h3>
65
  <p>{poi["explanation"]}</p>
66
  </div>
main.py CHANGED
@@ -361,13 +361,19 @@ def create_main_app(self):
361
 
362
  # ADVANCED SURVEY
363
  with gr.Column(visible=False) as advanced_survey_block:
364
- gr.Markdown("## Valuta questa spiegazione della raccomandazione")
 
 
 
365
 
366
  # Stato per tenere traccia del gruppo corrente
367
  advanced_current_group_idx = gr.State(0)
368
 
369
  # Carica i dati del questionario
370
- from utils.survey_utils import LIKERT_OPTIONS, SURVEY_STATEMENTS
 
 
 
371
 
372
  # Contenitori per i gruppi di affermazioni
373
  advanced_containers = []
@@ -379,7 +385,10 @@ def create_main_app(self):
379
  max_statements_per_group = 2 # Per i primi due gruppi
380
  for i in range(3):
381
  with gr.Column(visible=(i == 0)) as container:
382
- gr.Markdown(f"### Parte {i + 1} di 3")
 
 
 
383
 
384
  group_responses = []
385
  # Creiamo spazio per il massimo numero di affermazioni possibili
@@ -815,6 +824,11 @@ if __name__ == "__main__":
815
  default=5,
816
  help="Number of top recommendations to show",
817
  )
 
 
 
 
 
818
  parser.add_argument(
819
  "--port", type=int, default=7860, help="Port to run the Gradio app on"
820
  )
 
361
 
362
  # ADVANCED SURVEY
363
  with gr.Column(visible=False) as advanced_survey_block:
364
+ if args.survey_language == "it":
365
+ gr.Markdown("## Valuta questa spiegazione della raccomandazione")
366
+ else:
367
+ gr.Markdown("## Rate this explanation of the recommendation")
368
 
369
  # Stato per tenere traccia del gruppo corrente
370
  advanced_current_group_idx = gr.State(0)
371
 
372
  # Carica i dati del questionario
373
+ from utils.survey_utils import SURVEY_OPTIONS
374
+
375
+ SURVEY_STATEMENTS = SURVEY_OPTIONS[args.survey_language].get("statements", {})
376
+ LIKERT_OPTIONS = SURVEY_OPTIONS[args.survey_language].get("likert_options", [])
377
 
378
  # Contenitori per i gruppi di affermazioni
379
  advanced_containers = []
 
385
  max_statements_per_group = 2 # Per i primi due gruppi
386
  for i in range(3):
387
  with gr.Column(visible=(i == 0)) as container:
388
+ if args.survey_language == "it":
389
+ gr.Markdown(f"### Parte {i + 1} di 3")
390
+ else:
391
+ gr.Markdown(f"### Part {i + 1} of 3")
392
 
393
  group_responses = []
394
  # Creiamo spazio per il massimo numero di affermazioni possibili
 
824
  default=5,
825
  help="Number of top recommendations to show",
826
  )
827
+ parser.add_argument(
828
+ "--survey_language",
829
+ choices=["it", "en"],
830
+ help="Language for the survey questions",
831
+ )
832
  parser.add_argument(
833
  "--port", type=int, default=7860, help="Port to run the Gradio app on"
834
  )
resources/survey_statements.json CHANGED
@@ -1,18 +1,38 @@
1
  {
2
- "statements": [
3
- "Mi ha aiutato a capire se mi piacerà quel posto.",
4
- "Mi ha fatto decidere più velocemente se mi piace quel posto.",
5
- "Mi ha fatto venire voglia di andare .",
6
- "Mi è piaciuto come scelgono il posto da consigliare.",
7
- "Mi ha fatto capire se i suggerimenti rispecchiano i miei gusti.",
8
- "Mi ha fatto capire perché mi consigliano quel posto.",
9
- "Mi ha fatto fidare del suggerimento."
10
- ],
11
- "likert_options": [
12
- "In disaccordo",
13
- "Parzialmente in disaccordo",
14
- "Neutrale",
15
- "Parzialmente d'accordo",
16
- "D'accordo"
17
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  }
 
1
  {
2
+ "it": {
3
+ "statements": [
4
+ "Mi ha aiutato a capire se mi piacerà quel posto.",
5
+ "Mi ha fatto decidere più velocemente se mi piace quel posto.",
6
+ "Mi ha fatto venire voglia di andare .",
7
+ "Mi è piaciuto come scelgono il posto da consigliare.",
8
+ "Mi ha fatto capire se i suggerimenti rispecchiano i miei gusti.",
9
+ "Mi ha fatto capire perché mi consigliano quel posto.",
10
+ "Mi ha fatto fidare del suggerimento."
11
+ ],
12
+ "likert_options": [
13
+ "In disaccordo",
14
+ "Parzialmente in disaccordo",
15
+ "Neutrale",
16
+ "Parzialmente d'accordo",
17
+ "D'accordo"
18
+ ]
19
+ },
20
+ "en": {
21
+ "statements": [
22
+ "It helped me understand whether I will like that place.",
23
+ "It made me decide more quickly whether I like that place.",
24
+ "It made me want to go there.",
25
+ "I liked how they choose the place to recommend.",
26
+ "It helped me understand whether the suggestions match my tastes.",
27
+ "It helped me understand why they recommend that place to me.",
28
+ "It made me trust the suggestion."
29
+ ],
30
+ "likert_options": [
31
+ "Disagree",
32
+ "Somewhat disagree",
33
+ "Neutral",
34
+ "Somewhat agree",
35
+ "Agree"
36
+ ]
37
+ }
38
  }
utils/recommender_poi_utils.py CHANGED
@@ -43,8 +43,9 @@ def display_recommendations(user_id: str, k: int = 10) -> list[dict]:
43
  random.shuffle(available_pois)
44
  recommendations = available_pois[:k]
45
 
46
- if LOADED_MOCK_EXPLANATIONS:
47
- for rec in recommendations:
 
48
  explanation = random.choice(LOADED_MOCK_EXPLANATIONS)
49
  rec["explanation"] = explanation.get("explanation", "")
50
  rec["explanation_type"] = explanation.get("explanation_type", -1)
@@ -114,7 +115,7 @@ def view_poi_details(
114
  html = create_poi_html(poi, user_id)
115
 
116
  # Ottieni il tipo di spiegazione dal POI
117
- explanation_type = poi.get("explanation_type", 0)
118
 
119
  # Salva le informazioni del POI corrente per il questionario
120
  poi_info = {
 
43
  random.shuffle(available_pois)
44
  recommendations = available_pois[:k]
45
 
46
+ if LOADED_MOCK_EXPLANATIONS:
47
+ for rec in recommendations:
48
+ if "explanation" not in rec:
49
  explanation = random.choice(LOADED_MOCK_EXPLANATIONS)
50
  rec["explanation"] = explanation.get("explanation", "")
51
  rec["explanation_type"] = explanation.get("explanation_type", -1)
 
115
  html = create_poi_html(poi, user_id)
116
 
117
  # Ottieni il tipo di spiegazione dal POI
118
+ explanation_type = poi.get("explanation_type", -1)
119
 
120
  # Salva le informazioni del POI corrente per il questionario
121
  poi_info = {
utils/survey_utils.py CHANGED
@@ -7,9 +7,7 @@ import gradio as gr
7
 
8
  RESOURCE_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "resources")
9
  with open(os.path.join(RESOURCE_DIR, "survey_statements.json"), "r") as f:
10
- survey_data = json.load(f)
11
- SURVEY_STATEMENTS = survey_data.get("statements", [])
12
- LIKERT_OPTIONS = survey_data.get("likert_options", [])
13
 
14
 
15
  def feedback_message():
 
7
 
8
  RESOURCE_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "resources")
9
  with open(os.path.join(RESOURCE_DIR, "survey_statements.json"), "r") as f:
10
+ SURVEY_OPTIONS = json.load(f)
 
 
11
 
12
 
13
  def feedback_message():