Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -364,6 +364,28 @@ def summarize(input_text):
|
|
364 |
summarization_result = summarizer(input_text)
|
365 |
return summarization_result[0]['summary_text']
|
366 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
# Define the function for translation
|
368 |
def translate(input_text, target_lang):
|
369 |
# Map the target language selected by the user to the corresponding language code
|
@@ -384,13 +406,15 @@ def translate(input_text, target_lang):
|
|
384 |
# Generate the translation
|
385 |
generated_tokens = translation_model.generate(
|
386 |
**model_inputs,
|
387 |
-
forced_bos_token_id=translation_tokenizer.lang_code_to_id[lang_code]
|
|
|
388 |
)
|
389 |
|
390 |
# Decode the generated tokens and return the translation
|
391 |
return translation_tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
|
392 |
|
393 |
|
|
|
394 |
# Create the Gradio interfaces for question-answering, summarization, and translation
|
395 |
qa_interface = gr.Interface(
|
396 |
fn=answer_question,
|
@@ -455,11 +479,40 @@ translation_interface = gr.Interface(
|
|
455 |
flagging_options=["Inappropriate Answer"]
|
456 |
)
|
457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
# Combine the interfaces into a tabbed interface
|
459 |
-
tabbed_interface = gr.TabbedInterface([qa_interface, summarization_interface, translation_interface
|
|
|
460 |
|
461 |
# Launch the tabbed interface
|
462 |
tabbed_interface.launch()
|
463 |
-
|
464 |
-
|
465 |
-
|
|
|
364 |
summarization_result = summarizer(input_text)
|
365 |
return summarization_result[0]['summary_text']
|
366 |
|
367 |
+
def pdf_summarize(company, model, topic):
|
368 |
+
# Check if the selected company and model are valid
|
369 |
+
if company not in ["Beko", "Siemen"]:
|
370 |
+
raise ValueError("Invalid company selected.")
|
371 |
+
if model not in ["WC712", "WV985", "WG44G290BB", "WG37b18KGF"]:
|
372 |
+
raise ValueError("Invalid model number selected.")
|
373 |
+
|
374 |
+
# Define the summarized text for different topics
|
375 |
+
summarization_texts = {
|
376 |
+
"Summarization of General Safety Instructions": "Never place the product on a carpet-covered floor. Unplug the product if it is not in use. The water supply and draining hoses must be securely fastened and remain undamaged. While there is still water inside the product, never open the loading door or remove the filter. Do not force open the locked loading door.",
|
377 |
+
"Summarization of Children's Safety": "Children may breathe in or swallow small parts, causing them to suffocate. Children should not play with the device. Packaging materials may be dangerous for children. Keep packaging materials in a safe place away from the reach of children.",
|
378 |
+
"Summarization of Restriction on User Group": "This product can be used by children who are at the age of 8 and over and people whose physical, sensory, or mental skills are not fully developed or who do not have the necessary required experience and knowledge as long as they are supervised or trained about the safe use of the product and its risks. Children of less than 3 years should be kept away unless continuously supervised.",
|
379 |
+
"Summarization of Energy Efficiency Tips": "To maximize energy efficiency, always use the washing machine with a full load of laundry. Avoid overloading the machine, as it can lead to decreased performance and higher energy consumption. Use cold water for washing whenever possible, as it saves energy and reduces the cost of heating water. Additionally, consider using the appropriate wash cycle for the type of laundry to minimize unnecessary energy usage. Regularly clean the lint filter and perform maintenance tasks to ensure the machine operates at its best efficiency."
|
380 |
+
}
|
381 |
+
|
382 |
+
# Check if the selected topic is valid
|
383 |
+
if topic not in summarization_texts:
|
384 |
+
raise ValueError("Invalid topic selected.")
|
385 |
+
|
386 |
+
# Return the summarized text for the selected topic
|
387 |
+
return summarization_texts[topic]
|
388 |
+
|
389 |
# Define the function for translation
|
390 |
def translate(input_text, target_lang):
|
391 |
# Map the target language selected by the user to the corresponding language code
|
|
|
406 |
# Generate the translation
|
407 |
generated_tokens = translation_model.generate(
|
408 |
**model_inputs,
|
409 |
+
forced_bos_token_id=translation_tokenizer.lang_code_to_id[lang_code],
|
410 |
+
max_new_tokens=50 # Adjust the value of max_new_tokens as per your preference
|
411 |
)
|
412 |
|
413 |
# Decode the generated tokens and return the translation
|
414 |
return translation_tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
|
415 |
|
416 |
|
417 |
+
|
418 |
# Create the Gradio interfaces for question-answering, summarization, and translation
|
419 |
qa_interface = gr.Interface(
|
420 |
fn=answer_question,
|
|
|
479 |
flagging_options=["Inappropriate Answer"]
|
480 |
)
|
481 |
|
482 |
+
summarization_topic_interface = gr.Interface(
|
483 |
+
fn=pdf_summarize,
|
484 |
+
inputs=[
|
485 |
+
gr.Dropdown(
|
486 |
+
["Beko", "Siemen"],
|
487 |
+
label="Select Company",
|
488 |
+
default="Beko"
|
489 |
+
),
|
490 |
+
gr.Dropdown(
|
491 |
+
["WC712", "WV985", "WG44G290BB", "WG37b18KGF"],
|
492 |
+
label="Select Model Number",
|
493 |
+
default="WC712"
|
494 |
+
),
|
495 |
+
gr.Dropdown(
|
496 |
+
["Summarization of General Safety Instructions", "Summarization of Children's Safety", "Summarization of Restriction on User Group"],
|
497 |
+
label="Select Topic for Summarization"
|
498 |
+
)
|
499 |
+
],
|
500 |
+
outputs=gr.Textbox(label="Summary", lines=3),
|
501 |
+
title="Washing Machine Manual Guide Help Desk - Summarization by Topic",
|
502 |
+
description="Summarize specific topics related to the washing machine manual guide!",
|
503 |
+
examples=[
|
504 |
+
["Beko", "WC712", "Summarization of General Safety Instructions"],
|
505 |
+
["Siemen", "WG37b18KGF", "Summarization of Children's Safety"],
|
506 |
+
["Beko", "WV985", "Summarization of Restriction on User Group"],
|
507 |
+
["Siemen", "WG44G290BB", "Summarization of Energy Efficiency Tips"]
|
508 |
+
|
509 |
+
],
|
510 |
+
flagging_options=["Inappropriate Answer"]
|
511 |
+
)
|
512 |
+
|
513 |
# Combine the interfaces into a tabbed interface
|
514 |
+
tabbed_interface = gr.TabbedInterface([qa_interface, summarization_interface, translation_interface, summarization_topic_interface],
|
515 |
+
["Question-Answering", "Text Summarization", "Translation", "Summarization by Topic"])
|
516 |
|
517 |
# Launch the tabbed interface
|
518 |
tabbed_interface.launch()
|
|
|
|
|
|