Deepak Sahu commited on
Commit
b2ed780
·
1 Parent(s): 38d1ee1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -56,20 +56,34 @@ def get_recommendation(book_title: str) -> dict:
56
  # label wise similarity
57
  label_similarity: dict = {book: score for book, score in zip(books, scores)}
58
  #
59
- book_summaries: list[str] = [f"**{book}** \n {summary}" for book, summary in zip(books, summaries)]
60
 
61
- response = [label_similarity, ] + book_summaries
62
- return response
63
  # Generate card-style HTML
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  return fake_summaries[0]
66
  # return str(value)
67
 
68
  # We instantiate the Textbox class
69
  textbox = gr.Textbox(label="Write random title", placeholder="The Man who knew", lines=2)
70
  # label = gr.Label(label="Result", num_top_classes=N_RECOMMENDS)
71
- output = [gr.Label(label="Result", num_top_classes=N_RECOMMENDS)] + [gr.Textbox(label="Recommendation") for i in range(N_RECOMMENDS)]
72
-
73
  demo = gr.Interface(fn=get_recommendation, inputs=textbox, outputs=output)
74
 
75
  demo.launch()
 
56
  # label wise similarity
57
  label_similarity: dict = {book: score for book, score in zip(books, scores)}
58
  #
59
+ # book_summaries: list[str] = [f"**{book}** \n {summary}" for book, summary in zip(books, summaries)]
60
 
61
+ # return response
 
62
  # Generate card-style HTML
63
 
64
+ html = "<div style='display: flex; flex-wrap: wrap; gap: 1rem;'>"
65
+ for book, summary in zip(books, summaries):
66
+ html += f"""
67
+ <div style='border: 1px solid #ddd; border-radius: 8px; padding: 1rem; width: 200px; box-shadow: 2px 2px 5px rgba(0,0,0,0.1);'>
68
+ <h3 style='margin: 0;'>{book}</h3>
69
+ <p style='font-size: 0.9rem; color: #555;'>{summaries}</p>
70
+ </div>
71
+ """
72
+ html += "</div>"
73
+
74
+ # Club the output to be processed by gradio
75
+ response = [label_similarity, html]
76
+
77
+ return response
78
+
79
  return fake_summaries[0]
80
  # return str(value)
81
 
82
  # We instantiate the Textbox class
83
  textbox = gr.Textbox(label="Write random title", placeholder="The Man who knew", lines=2)
84
  # label = gr.Label(label="Result", num_top_classes=N_RECOMMENDS)
85
+ # output = [gr.Label(label="Result", num_top_classes=N_RECOMMENDS)] + [gr.Textbox(label="Recommendation") for i in range(N_RECOMMENDS)]
86
+ output = [gr.Label(label="Similarity"), gr.HTML(label="Books Descriptions")]
87
  demo = gr.Interface(fn=get_recommendation, inputs=textbox, outputs=output)
88
 
89
  demo.launch()