TheHickman commited on
Commit
90d2f9c
·
verified ·
1 Parent(s): 8075d5e

Added summarisation

Browse files
Files changed (1) hide show
  1. app.py +53 -8
app.py CHANGED
@@ -230,21 +230,66 @@ context = "My name is Merve and I live in İstanbul."
230
  qa_model(question = question, context = context)
231
  ## {{'answer': 'İstanbul', 'end': 39, 'score': 0.953, 'start': 31}}
232
  </pre>
 
233
  """
234
 
235
- SUMMARISATION = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
 
237
  # ---- Placeholder HTML pages ----
238
  TEXT_GENERATION_HTML = TEXT_GENERATION
239
 
240
  QUESTION_ANSWER_HTML = QUESTION_ANSWER
241
 
242
- SUMMARISATION_HTML = """
243
- <div style="max-width: 800px; margin: auto;">
244
- <h1>Summarisation</h1>
245
- <p>Summarisation content goes here...</p>
246
- </div>
247
- """
248
 
249
  IMAGE_GENERATION_HTML = """
250
  <div style="max-width: 800px; margin: auto;">
@@ -258,7 +303,7 @@ def switch_content(choice):
258
 
259
  pages = {
260
  "Text Generation": TEXT_GENERATION_HTML,
261
- "Question and Answer": QUESTION_ANSWER_HTML,
262
  "Summarisation": SUMMARISATION_HTML,
263
  "Image Generation": IMAGE_GENERATION_HTML,
264
  }
 
230
  qa_model(question = question, context = context)
231
  ## {{'answer': 'İstanbul', 'end': 39, 'score': 0.953, 'start': 31}}
232
  </pre>
233
+ </div>
234
  """
235
 
236
+ SUMMARISATION = f"""
237
+ <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
238
+ <h1>Summarisation (Hugging Face)</h1>
239
+ <p>
240
+ Summarization is the task of producing a shorter version of a document while preserving its important information.
241
+ Some models can extract text from the original input, while other models can generate entirely new text.
242
+ </p>
243
+ {IMAGE_HTML}
244
+ <h1>About Summarisation</h1>
245
+ <h2>Use Cases</h2>
246
+ <h3>Research Paper Summarization 🧐</h3>
247
+ <p>
248
+ Research papers can be summarized to allow researchers to spend less time selecting which articles to read.
249
+ There are several approaches you can take for a task like this:
250
+ <ol>
251
+ <li>Use an existing extractive summarization model on the Hub to do inference.</li>
252
+ <li>Pick an existing language model trained for academic papers. This model can then be trained in a process called fine-tuning so it can solve the summarization task.</li>
253
+ <li>Use a sequence-to-sequence model like T5 for abstractive text summarization.</li>
254
+ </ol>
255
+ </p>
256
+ <h3>Inference</h3>
257
+ <p>
258
+ You can use the 🤗 Transformers library summarization pipeline to infer with existing Summarization models.
259
+ If no model name is provided the pipeline will be initialized with <a href="https://huggingface.co/sshleifer/distilbart-cnn-12-6">sshleifer/distilbart-cnn-12-6</a>.
260
+ </p>
261
+ <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
262
+ from transformers import pipeline
263
+
264
+ classifier = pipeline("summarization")
265
+ classifier("Paris is the capital and most populous city of France, with an estimated population of 2,175,601 residents as of 2018, in an area of more than 105 square kilometres (41 square miles). The City of Paris is the centre and seat of government of the region and province of Île-de-France, or Paris Region, which has an estimated population of 12,174,880, or about 18 percent of the population of France as of 2017.")
266
+ ## [{{ "summary_text": " Paris is the capital and most populous city of France..." }}]
267
+ </pre>
268
+
269
+ <p>
270
+ You can use <a href="https://github.com/huggingface/huggingface.js">huggingface.js</a> to infer summarization models on Hugging Face Hub.
271
+ </p>
272
+ <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
273
+ import {{ InferenceClient }} from "@huggingface/inference";
274
+
275
+ const inference = new InferenceClient(HF_TOKEN);
276
+ const inputs =
277
+ "Paris is the capital and most populous city of France, with an estimated population of 2,175,601 residents as of 2018, in an area of more than 105 square kilometres (41 square miles). The City of Paris is the centre and seat of government of the region and province of Île-de-France, or Paris Region, which has an estimated population of 12,174,880, or about 18 percent of the population of France as of 2017.";
278
+
279
+ await inference.summarization({{
280
+ model: "sshleifer/distilbart-cnn-12-6",
281
+ inputs,
282
+ }});
283
+ </pre>
284
+ </div>
285
+ """
286
 
287
  # ---- Placeholder HTML pages ----
288
  TEXT_GENERATION_HTML = TEXT_GENERATION
289
 
290
  QUESTION_ANSWER_HTML = QUESTION_ANSWER
291
 
292
+ SUMMARISATION_HTML = SUMMARISE
 
 
 
 
 
293
 
294
  IMAGE_GENERATION_HTML = """
295
  <div style="max-width: 800px; margin: auto;">
 
303
 
304
  pages = {
305
  "Text Generation": TEXT_GENERATION_HTML,
306
+ "Question Answering": QUESTION_ANSWER_HTML,
307
  "Summarisation": SUMMARISATION_HTML,
308
  "Image Generation": IMAGE_GENERATION_HTML,
309
  }