Deepak Sahu commited on
Commit
acffe44
·
1 Parent(s): e60054b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -29
app.py CHANGED
@@ -2,9 +2,6 @@
2
  CLEAN_DF_UNIQUE_TITLES = "unique_titles_books_summary.csv"
3
  N_RECOMMENDS = 5
4
 
5
- # def get_recommendation(book_title: str) -> str:
6
- # return book_title
7
-
8
  # from transformers import pipeline, set_seed
9
 
10
  # # CONST
@@ -14,19 +11,6 @@ N_RECOMMENDS = 5
14
 
15
  # generator_model = pipeline('text-generation', model=TRAINED_CASUAL_MODEL)
16
 
17
-
18
-
19
- # def sanity_check():
20
- # '''Validates whether the vectors count is of same as summaries present else RAISES Error
21
- # '''
22
- # global BOOKS_CSV, SUMMARY_VECTORS
23
- # df = get_dataframe(BOOKS_CSV)
24
- # vectors = np.load(SUMMARY_VECTORS)
25
- # assert df.shape[0] == vectors.shape[0]
26
-
27
-
28
- # Reference: https://huggingface.co/learn/nlp-course/en/chapter9/2
29
-
30
  import gradio as gr
31
  from z_similarity import computes_similarity_w_hypothetical
32
  from z_hypothetical_summary import generate_summaries
@@ -36,10 +20,6 @@ books_df = get_dataframe(CLEAN_DF_UNIQUE_TITLES)
36
 
37
 
38
  def get_recommendation(book_title: str) -> dict:
39
- global generator_model
40
- # return "Hello"
41
- # # Generate hypothetical summary
42
- # value = generator_model("hello", max_length=50)
43
  fake_summaries = generate_summaries(book_title=book_title, n_samples=5) # other parameters are set to default in the function
44
 
45
  # Compute Simialrity
@@ -58,31 +38,25 @@ def get_recommendation(book_title: str) -> dict:
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
  html = "<div style='display: flex; flex-wrap: wrap; gap: 1rem;'>"
64
  for book, summary in zip(books, summaries):
65
  html += f"""
66
  <div style='border: 1px solid #ddd; border-radius: 8px; padding: 1rem; width: 200px; box-shadow: 2px 2px 5px rgba(0,0,0,0.1);'>
67
  <h3 style='margin: 0;'>{book}</h3>
68
- <p style='font-size: 0.9rem; color: #555;'>{summaries}</p>
69
  </div>
70
  """
71
  html += "</div>"
72
 
73
  # Club the output to be processed by gradio
74
- response = [label_similarity, ] #html]
75
 
76
  return response
77
 
78
- return fake_summaries[0]
79
- # return str(value)
80
-
81
  # We instantiate the Textbox class
82
  textbox = gr.Textbox(label="Write random title", placeholder="The Man who knew", lines=2)
83
- # label = gr.Label(label="Result", num_top_classes=N_RECOMMENDS)
84
- # output = [gr.Label(label="Result", num_top_classes=N_RECOMMENDS)] + [gr.Textbox(label="Recommendation") for i in range(N_RECOMMENDS)]
85
- output = [gr.Label(label="Similarity"), ] # gr.HTML(label="Books Descriptions")]
86
  demo = gr.Interface(fn=get_recommendation, inputs=textbox, outputs=output)
87
 
88
  demo.launch()
 
2
  CLEAN_DF_UNIQUE_TITLES = "unique_titles_books_summary.csv"
3
  N_RECOMMENDS = 5
4
 
 
 
 
5
  # from transformers import pipeline, set_seed
6
 
7
  # # CONST
 
11
 
12
  # generator_model = pipeline('text-generation', model=TRAINED_CASUAL_MODEL)
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  import gradio as gr
15
  from z_similarity import computes_similarity_w_hypothetical
16
  from z_hypothetical_summary import generate_summaries
 
20
 
21
 
22
  def get_recommendation(book_title: str) -> dict:
 
 
 
 
23
  fake_summaries = generate_summaries(book_title=book_title, n_samples=5) # other parameters are set to default in the function
24
 
25
  # Compute Simialrity
 
38
  #
39
  # book_summaries: list[str] = [f"**{book}** \n {summary}" for book, summary in zip(books, summaries)]
40
 
 
41
  # Generate card-style HTML
42
  html = "<div style='display: flex; flex-wrap: wrap; gap: 1rem;'>"
43
  for book, summary in zip(books, summaries):
44
  html += f"""
45
  <div style='border: 1px solid #ddd; border-radius: 8px; padding: 1rem; width: 200px; box-shadow: 2px 2px 5px rgba(0,0,0,0.1);'>
46
  <h3 style='margin: 0;'>{book}</h3>
47
+ <p style='font-size: 0.9rem; color: #555;'>{summary}</p>
48
  </div>
49
  """
50
  html += "</div>"
51
 
52
  # Club the output to be processed by gradio
53
+ response = [label_similarity, html]
54
 
55
  return response
56
 
 
 
 
57
  # We instantiate the Textbox class
58
  textbox = gr.Textbox(label="Write random title", placeholder="The Man who knew", lines=2)
59
+ output = [gr.Label(label="Similarity"), gr.HTML(label="Books Descriptions")]
 
 
60
  demo = gr.Interface(fn=get_recommendation, inputs=textbox, outputs=output)
61
 
62
  demo.launch()