bibinsee's picture
Update app.py
40111a9
raw
history blame contribute delete
No virus
19.6 kB
text_Beko_WC712 = """General safetyinstructions_
This section includes security instructions which may help prevent
the injuries and material damage risks AIl kinds of warranties shal
be invalid if these instructions are not observed,
1.1Life and property safety
Never place the product on a carpet-covered floor: Electrical parts
will get overheated since air cannot circulate from under the device
This wil cause problems with your product;
Unplug the productif itisnotin use
Always have the instalation and repairing procedures carried out
by the Authorized Service Agent; Manufacturer shall not be held
Iiable for damages that may arise from procedures carried out by
unauthorized persons;
The water supply and draining hosesmustbesecurely fastened and
remain undamaged; Otherwise, waterleak may occur,
While there is stil water inside the product, never open the loading
door or remove the filter Otherwise,risk of flooding and injury from
hot water wiloccur,
Donotforce open thelocked loading door Door can be opened a few
minutes after the washing cycle ends In case of forcing the loading
door to open, the door and the lock mechanism may get damaged;
Use detergents, softeners and supplements suitable for automatic
washing machines only:
Follow the instructions on the label of textiles and the detergent
package"""
text_Beko_WV985 = """1.2 Children's safety
This product canbe used by the children who are at the age of 8 and
over and the people whose physical, sensory or mental skills are not
fully developed or who do not have necessary required experience
and knowledge as long as they are supervised or trained about the
safeuse oftheproduct anditsrisks Children shouldnotplaywith the
device: Cleaning and maintenance works should not be performed
by children unless they are supervised by someone; Children of less
than 3years should bekept away unless continuously supervised;
Packaging materials may be dangerous for the children . Keep
packaging materials in a safe place away from reach of the children
Washing Machine / Users Manual"""
text_Siemen_WG44G290BB = """Washing machine
WG44G290GB
en
User manual and installation instructions
Register your product on My Siemens and discover
exclusive services and offers.
siemens-home.bsh-group.com/welcome
The future moving in.
Siemens Home Appliances
en
Safety
4
1 Safety
Observe the following safety instructions.
1.1 General information
!
Read this instruction manual carefully.
!
Keep the instruction manual and the product information safe
for future reference or for the next owner.
!
Do not connect the appliance if it has been damaged in transit.
1.2 Intended use
Only use this appliance:
!
For washing machine-washable fabrics and hand-washable wool
in accordance with the care label.
!
With tap water and commercially available detergents and care
products suitable for washing machines.
!
In private households and in enclosed spaces in a domestic en-
vironment.
!
Up to an altitude of max. 4000 m above sea level.
1.3 Restriction on user group
This appliance may be used by children aged 8 or over and by
people who have reduced physical, sensory or mental abilities or
inadequate experience and/or knowledge, provided that they are
supervised or have been instructed on how to use the appliance
safely and have understood the resulting dangers.
Do not let children play with the appliance.
Cleaning and user maintenance must not be performed by chil-
dren unless they are being supervised.
Keep children under the age of 3 years and pets away from the
appliance.
Safety
en
5
1.4 Safe installation
Take note of the safety instructions when installing the appliance.
WARNING - Risk of electric shock!
Incorrect installation is dangerous.
>
Connect and operate the appliance only in accordance with the
specifications on the rating plate.
>
Connect the appliance to a power supply with alternating cur-
rent only via a properly installed socket with earthing.
>
The protective conductor system of the domestic electrical in-
stallation must be properly installed. The installation must have
a sufficiently large cross section.
>
When using a residual current circuit breaker, only use a type
with the
mark.
>
Never equip the appliance with an external switching device,
e.g. a timer or remote control.
>
When the appliance is installed, the mains plug of the power
cord must be freely accessible. If free access is not possible, an
all-pole isolating switch must be installed in the permanent elec-
trical installation according to the installation regulations.
>
When installing the appliance, check that the power cable is not
trapped or damaged.
If the insulation of the power cord is damaged, this is dangerous.
>
Never let the power cord come into contact with hot appliance
parts or heat sources.
>
Never let the power cord come into contact with sharp points or
edges.
>
Never kink, crush or modify the power cord.
WARNING - Risk of fire!
It is dangerous to use an extended power cord and non-approved
adapters.
>
Do not use extension cables or multiple socket strips.
>
Only use adapters and power cords approved by the manufac-
turer."""
text_Siemen_WG37b18KGF = """Safety
6
>
If the power cord is too short and a longer one is not available,
please contact an electrician to have the domestic installation
adapted.
WARNING - Risk of injury!
The high weight of the appliance may result in injury when lifted.
>
Do not lift the appliance on your own.
If this appliance is not correctly installed in a washer-dryer stack,
the installed appliance may fall.
>
Only stack the dryer on a washing machine using the connec-
tion kit from the dryer manufacturer . No other installation
method is permitted.
>
Do not install the appliance in a washer-dryer stack if the dryer
manufacturer does not offer a suitable connection kit.
>
Do not install appliances from different manufacturers and with
varying depths and widths in a washer-dryer stack.
>
Do not install a washer-dryer stack on a platform; the appli-
ances may tip over.
WARNING - Risk of suffocation!
Children may put packaging material over their heads or wrap
themselves up in it and suffocate.
>
Keep packaging material away from children.
>
Do not let children play with packaging material.
CAUTION - Risk of injury!
The appliance may vibrate or move when in use.
>
Place the appliance on a clean, even, solid surface.
>
Align the appliance using the appliance feet and a spirit level.
If hoses and power cords have been laid incorrectly, this causes a
tripping hazard.
>
Lay hoses and power cords in such a way that there is no risk
of tripping.
If the appliance is moved by holding onto protruding components,
such as the appliance door, the parts may break off.
>
Do not move the appliance by holding onto protruding parts.
Safety
en
7
CAUTION - Risk of cutting!
Touching sharp edges on the appliance may lead to cuts.
>
Do not touch the sharp edges on the appliance.
>
Wear protective gloves when installing and transporting the ap-
pliance.
1.5 Safe use
WARNING - Risk of electric shock!
If the appliance or the power cord is damaged, this is dangerous.
>
Never operate a damaged appliance.
>
Never pull on the power cord to unplug the appliance. Always
unplug the appliance at the mains.
>
If the appliance or the power cord is damaged, immediately un-
plug the power cord or switch off the fuse in the fuse box and
turn off the water tap.
>
Call customer services. -
Page 50
An ingress of moisture can cause an electric shock.
>
Only use the appliance in enclosed spaces.
>
Never expose the appliance to intense heat or humidity.
>
Do not use steam- or high-pressure cleaners, hoses or sprays
to clean the appliance.
WARNING - Risk of harm to health!
Children can lock themselves in the appliance, there by putting
their lives at risk.
>
Do not install the appliance behind a door as this may obstruct
the appliance door or prevent it from opening.
>
With redundant appliances, unplug the power cord. Then cut
through the cord and damage the lock on the appliance door
beyond repair so that the appliance door will no longer close.
WARNING - Risk of suffocation!
Children may breathe in or swallow small parts, causing them to
suffocate.
>
Keep small parts away from children.
>
Do not let children play with small parts.
Childproof lock
en
33
3.
Wipe the rubber gasket dry and re-
move any foreign objects.
4.
Leave the appliance door and de-
tergent drawer open so that resid-
ual water can evaporate.
14 Childproof lock
Secure your appliance against being
operated unintentionally using the
controls.
14.1 Activating the childproof
lock
>
Press and hold the two
3 s
but-
tons for approx. 3 seconds.
a
The display shows
.
a
The controls are locked.
a
The childproof lock remains active
even after the appliance has been
switched off and in the event of a
power failure.
14.2 Deactivating the child-
proof lock
Requirement:
To deactivate the
childproof lock, the appliance must
be switched on.
>
Press and hold the two
3 s
but-
tons for approx. 3 seconds.
a
goes out in the display."""
from transformers import pipeline, MBartForConditionalGeneration, MBart50TokenizerFast
import gradio as gr
# Load the question-answering pipeline
question_answerer = pipeline("question-answering", model='distilbert-base-uncased-distilled-squad')
# Load the summarization pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Load the translation model and tokenizer
translation_model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-one-to-many-mmt")
translation_tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-one-to-many-mmt", src_lang="en_XX")
# Define the function for question-answering
def answer_question(company, model, question):
if company == "Beko":
if model == "WC712":
context = text_Beko_WC712
elif model == "WV985":
context = text_Beko_WV985
else:
raise ValueError("Invalid model number selected.")
elif company == "Siemen":
if model == "WG44G290BB":
context = text_Siemen_WG44G290BB
elif model == "WG37b18KGF":
context = text_Siemen_WG37b18KGF
else:
raise ValueError("Invalid model number selected.")
else:
raise ValueError("Invalid company selected.")
qa_result = question_answerer(question=question, context=context)
return qa_result['answer']
# Define the function for summarization
def summarize(input_text):
summarization_result = summarizer(input_text)
return summarization_result[0]['summary_text']
def pdf_summarize(company, model, topic):
# Check if the selected company and model are valid
if company not in ["Beko", "Siemen"]:
raise ValueError("Invalid company selected.")
if model not in ["WC712", "WV985", "WG44G290BB", "WG37b18KGF"]:
raise ValueError("Invalid model number selected.")
# Define the summarized text for different topics
summarization_texts = {
"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.",
"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.",
"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.",
"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."
}
# Check if the selected topic is valid
if topic not in summarization_texts:
raise ValueError("Invalid topic selected.")
# Return the summarized text for the selected topic
return summarization_texts[topic]
# Define the function for translation
def translate(input_text, target_lang):
# Map the target language selected by the user to the corresponding language code
lang_mapping = {
"Malayalam": "ml",
"Tamil": "ta",
"Hindi": "hi",
"Gujarati": "gu",
"Bengali": "bn",
"Marathi": "mr",
"Telugu": "te"
}
lang_code = f"{lang_mapping[target_lang]}_IN"
# Tokenize the input text
model_inputs = translation_tokenizer(input_text, return_tensors="pt")
# Generate the translation
generated_tokens = translation_model.generate(
**model_inputs,
forced_bos_token_id=translation_tokenizer.lang_code_to_id[lang_code],
max_new_tokens=50 # Adjust the value of max_new_tokens as per your preference
)
# Decode the generated tokens and return the translation
return translation_tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
# Create the Gradio interfaces for question-answering, summarization, and translation
qa_interface = gr.Interface(
fn=answer_question,
inputs=[
gr.Dropdown(
["Beko", "Siemen"],
label="Select Company",
default="Beko"
),
gr.Dropdown(
["WC712", "WV985", "WG44G290BB", "WG37b18KGF"],
label="Select Model Number",
default="WC712"
),
gr.Textbox(label="Question", placeholder="Enter your question here...")
],
outputs=gr.Textbox(label="Answer"),
title="Washing Machine Manual Guide Help Desk - Question-Answering",
description="Ask any question related to the washing machine manual guide and get answers! Powered by `distilbert-base-uncased-distilled-squad` model.",
examples=[
["Beko", "WC712", "Does the manufacturer hold liable for damages that may arise from procedures carried out by unauthorized persons?"],
["Beko", "WV985", "At what age can children use the product?"],
["Siemen", "WG44G290BB", "What is the maximum altitude intended for use?"],
["Siemen", "WG37b18KGF", "What should we do if the power cord is too short and a longer one is not available?"]
],
flagging_options=["Inappropriate Answer"]
)
summarization_interface = gr.Interface(
fn=summarize,
inputs=[gr.Textbox(label="Don't have time? Looking for an abstract? Paste any text to summarize and get it done quickly!", lines=6, placeholder="Paste any text to summarize here...")],
outputs=gr.Textbox(label="Summary", lines=3),
title="Washing Machine Manual Guide Help Desk - Text Summarization",
description="Summarize any text using the `facebook/bart-large-cnn` model under the hood!",
examples=[
["This product can be used by the children who are at the age of 8 and over and the people whose physical, sensory or mental skills are not fully developed or who do not have necessary required experience and knowledge as long as they are supervised or trained about the safe use oftheproduct anditsrisks Children shouldnotplaywith the device: Cleaning and maintenance works should not be performed by children unless they are supervised by someone. Children of less than 3 years should bekept away unless continuously supervised. Packaging materials may be dangerous for the children . Keep packaging materials in a safe place away from reach of the children"]
],
flagging_options=["Inappropriate Answer"]
)
# Define the target languages for translation
target_languages = ["Tamil", "Malayalam", "Telugu", "Marathi", "Gujarati", "Hindi", "Bengali"]
translation_interface = gr.Interface(
fn=translate,
inputs=[
gr.Textbox(label="Enter text to translate here...", lines=6, placeholder="Paste any text to translate here..."),
gr.Dropdown(target_languages, label="Select Target Language")
],
outputs=gr.Textbox(label="Translation"),
title="Washing Machine Manual Guide Help Desk - Translation",
description="Translate the text from English to the selected local language. Powered by `facebook/mbart-large-50-one-to-many-mmt` model",
examples=[
["Do not install the appliance behind a door as this may obstruct the appliance door or prevent it from opening", "Tamil"],
["Leave the appliance door and detergent drawer open so that residual water can evaporate", "Malayalam"],
["Children may breathe in or swallow small parts, causing them to suffocate", "Telugu"],
["Never expose the appliance to intense heat or humidity", "Marathi"],
["If the appliance or the power cord is damaged, immediately unplug the power cord or switch off the fuse in the fuse box and turn off the water tap", "Gujarati"],
["Do not touch the sharp edges on the appliance", "Hindi"],
["Keep the instruction manual and the product information safe for future reference or for the next owner", "Bengali"]
],
flagging_options=["Inappropriate Answer"]
)
summarization_topic_interface = gr.Interface(
fn=pdf_summarize,
inputs=[
gr.Dropdown(
["Beko", "Siemen"],
label="Select Company",
default="Beko"
),
gr.Dropdown(
["WC712", "WV985", "WG44G290BB", "WG37b18KGF"],
label="Select Model Number",
default="WC712"
),
gr.Dropdown(
["Summarization of General Safety Instructions", "Summarization of Children's Safety", "Summarization of Restriction on User Group"],
label="Select Topic for Summarization"
)
],
outputs=gr.Textbox(label="Summary", lines=3),
title="Washing Machine Manual Guide Help Desk - Summarization by Topic",
description="Summarize specific topics related to the washing machine manual guide!",
examples=[
["Beko", "WC712", "Summarization of General Safety Instructions"],
["Siemen", "WG37b18KGF", "Summarization of Children's Safety"],
["Beko", "WV985", "Summarization of Restriction on User Group"],
["Siemen", "WG44G290BB", "Summarization of Energy Efficiency Tips"]
],
flagging_options=["Inappropriate Answer"]
)
# Combine the interfaces into a tabbed interface
tabbed_interface = gr.TabbedInterface([qa_interface, summarization_interface, translation_interface, summarization_topic_interface],
["Question-Answering", "Text Summarization", "Translation", "Summarization by Topic"])
# Launch the tabbed interface
tabbed_interface.launch()