Deepak Sahu commited on
Commit
e77e4c7
·
1 Parent(s): 0b99bf5

different output view

Browse files
Files changed (2) hide show
  1. app.py +19 -4
  2. z_embedding.py +1 -1
app.py CHANGED
@@ -50,9 +50,23 @@ def get_recommendation(book_title: str) -> dict:
50
  df_ranked = df_ranked.reset_index()
51
 
52
  books = df_ranked["book_name"].to_list()[:N_RECOMMENDS]
 
53
  scores = similarity[ranks][:N_RECOMMENDS]
54
- print(scores)
55
- print(type(scores))
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  return {book: score for book, score in zip(books, scores)} # referene: https://huggingface.co/docs/hub/en/spaces-sdks-gradio
58
 
@@ -61,8 +75,9 @@ def get_recommendation(book_title: str) -> dict:
61
 
62
  # We instantiate the Textbox class
63
  textbox = gr.Textbox(label="Write random title", placeholder="The Man who knew", lines=2)
64
- label = gr.Label(label="Result", num_top_classes=N_RECOMMENDS)
 
65
 
66
- demo = gr.Interface(fn=get_recommendation, inputs=textbox, outputs=label)
67
 
68
  demo.launch()
 
50
  df_ranked = df_ranked.reset_index()
51
 
52
  books = df_ranked["book_name"].to_list()[:N_RECOMMENDS]
53
+ summaries = df_ranked["summaries"].to_list()[:N_RECOMMENDS]
54
  scores = similarity[ranks][:N_RECOMMENDS]
55
+
56
+ output_data_model: list[dict] = [ {"Book": b, "Similarity Score": s, "Description": d} for b, s, d in zip(books, summaries, scores)]
57
+
58
+ # Generate card-style HTML
59
+ html = "<div style='display: flex; flex-wrap: wrap; gap: 1rem;'>"
60
+ for rec in output_data_model:
61
+ html += f"""
62
+ <div style='border: 1px solid #ddd; border-radius: 8px; padding: 1rem; width: 200px; box-shadow: 2px 2px 5px rgba(0,0,0,0.1);'>
63
+ <h3 style='margin: 0;'>{rec['Book']}</h3>
64
+ <p style='margin: 0.5rem 0;'>Similarity Score: {rec['Similarity Score']}</p>
65
+ <p style='font-size: 0.9rem; color: #555;'>{rec['Description']}</p>
66
+ </div>
67
+ """
68
+ html += "</div>"
69
+ return html
70
 
71
  return {book: score for book, score in zip(books, scores)} # referene: https://huggingface.co/docs/hub/en/spaces-sdks-gradio
72
 
 
75
 
76
  # We instantiate the Textbox class
77
  textbox = gr.Textbox(label="Write random title", placeholder="The Man who knew", lines=2)
78
+ # label = gr.Label(label="Result", num_top_classes=N_RECOMMENDS)
79
+ output = gr.HTML(label="Recommended Books")
80
 
81
+ demo = gr.Interface(fn=get_recommendation, inputs=textbox, outputs=output)
82
 
83
  demo.launch()
z_embedding.py CHANGED
@@ -14,7 +14,7 @@ CACHE_SUMMARY_EMB_NPY = "app_cache/summary_vectors.npy"
14
 
15
  import gradio as gr
16
 
17
- if gr.NO_RELOAD:
18
  model = SentenceTransformer(EMB_MODEL)
19
 
20
 
 
14
 
15
  import gradio as gr
16
 
17
+ if gr.NO_RELOAD: # Required for faster working with HF spaces
18
  model = SentenceTransformer(EMB_MODEL)
19
 
20