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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ text_Beko_WC712 = """General safetyinstructions_
2
+ This section includes security instructions which may help prevent
3
+ the injuries and material damage risks AIl kinds of warranties shal
4
+ be invalid if these instructions are not observed,
5
+ 1.1Life and property safety
6
+ Never place the product on a carpet-covered floor: Electrical parts
7
+ will get overheated since air cannot circulate from under the device
8
+ This wil cause problems with your product;
9
+ Unplug the productif itisnotin use
10
+ Always have the instalation and repairing procedures carried out
11
+ by the Authorized Service Agent; Manufacturer shall not be held
12
+ Iiable for damages that may arise from procedures carried out by
13
+ unauthorized persons;
14
+ The water supply and draining hosesmustbesecurely fastened and
15
+ remain undamaged; Otherwise, waterleak may occur,
16
+ While there is stil water inside the product, never open the loading
17
+ door or remove the filter Otherwise,risk of flooding and injury from
18
+ hot water wiloccur,
19
+ Donotforce open thelocked loading door Door can be opened a few
20
+ minutes after the washing cycle ends In case of forcing the loading
21
+ door to open, the door and the lock mechanism may get damaged;
22
+ Use detergents, softeners and supplements suitable for automatic
23
+ washing machines only:
24
+ Follow the instructions on the label of textiles and the detergent
25
+ package"""
26
+
27
+
28
+ text_Beko_WV985 = """1.2 Children's safety
29
+ This product canbe used by the children who are at the age of 8 and
30
+ over and the people whose physical, sensory or mental skills are not
31
+ fully developed or who do not have necessary required experience
32
+ and knowledge as long as they are supervised or trained about the
33
+ safeuse oftheproduct anditsrisks Children shouldnotplaywith the
34
+ device: Cleaning and maintenance works should not be performed
35
+ by children unless they are supervised by someone; Children of less
36
+ than 3years should bekept away unless continuously supervised;
37
+ Packaging materials may be dangerous for the children . Keep
38
+ packaging materials in a safe place away from reach of the children
39
+ Washing Machine / Users Manual"""
40
+
41
+
42
+ text_Siemen_WG44G290BB = """Washing machine
43
+ WG44G290GB
44
+ en
45
+ User manual and installation instructions
46
+ Register your product on My Siemens and discover
47
+ exclusive services and offers.
48
+ siemens-home.bsh-group.com/welcome
49
+ The future moving in.
50
+ Siemens Home Appliances
51
+ en
52
+ Safety
53
+ 4
54
+
55
+ 1 Safety
56
+ Observe the following safety instructions.
57
+
58
+ 1.1 General information
59
+ !
60
+ Read this instruction manual carefully.
61
+ !
62
+ Keep the instruction manual and the product information safe
63
+ for future reference or for the next owner.
64
+ !
65
+ Do not connect the appliance if it has been damaged in transit.
66
+
67
+ 1.2 Intended use
68
+ Only use this appliance:
69
+ !
70
+ For washing machine-washable fabrics and hand-washable wool
71
+ in accordance with the care label.
72
+ !
73
+ With tap water and commercially available detergents and care
74
+ products suitable for washing machines.
75
+ !
76
+ In private households and in enclosed spaces in a domestic en-
77
+ vironment.
78
+ !
79
+ Up to an altitude of max. 4000 m above sea level.
80
+
81
+ 1.3 Restriction on user group
82
+ This appliance may be used by children aged 8 or over and by
83
+ people who have reduced physical, sensory or mental abilities or
84
+ inadequate experience and/or knowledge, provided that they are
85
+ supervised or have been instructed on how to use the appliance
86
+ safely and have understood the resulting dangers.
87
+ Do not let children play with the appliance.
88
+ Cleaning and user maintenance must not be performed by chil-
89
+ dren unless they are being supervised.
90
+ Keep children under the age of 3 years and pets away from the
91
+ appliance.
92
+ Safety
93
+ en
94
+ 5
95
+
96
+ 1.4 Safe installation
97
+ Take note of the safety instructions when installing the appliance.
98
+ WARNING - Risk of electric shock!
99
+ Incorrect installation is dangerous.
100
+
101
+ >
102
+ Connect and operate the appliance only in accordance with the
103
+ specifications on the rating plate.
104
+
105
+ >
106
+ Connect the appliance to a power supply with alternating cur-
107
+ rent only via a properly installed socket with earthing.
108
+
109
+ >
110
+ The protective conductor system of the domestic electrical in-
111
+ stallation must be properly installed. The installation must have
112
+ a sufficiently large cross section.
113
+
114
+ >
115
+ When using a residual current circuit breaker, only use a type
116
+ with the
117
+ mark.
118
+
119
+ >
120
+ Never equip the appliance with an external switching device,
121
+ e.g. a timer or remote control.
122
+
123
+ >
124
+ When the appliance is installed, the mains plug of the power
125
+ cord must be freely accessible. If free access is not possible, an
126
+ all-pole isolating switch must be installed in the permanent elec-
127
+ trical installation according to the installation regulations.
128
+
129
+ >
130
+ When installing the appliance, check that the power cable is not
131
+ trapped or damaged.
132
+ If the insulation of the power cord is damaged, this is dangerous.
133
+
134
+ >
135
+ Never let the power cord come into contact with hot appliance
136
+ parts or heat sources.
137
+
138
+ >
139
+ Never let the power cord come into contact with sharp points or
140
+ edges.
141
+
142
+ >
143
+ Never kink, crush or modify the power cord.
144
+ WARNING - Risk of fire!
145
+ It is dangerous to use an extended power cord and non-approved
146
+ adapters.
147
+
148
+ >
149
+ Do not use extension cables or multiple socket strips.
150
+
151
+ >
152
+ Only use adapters and power cords approved by the manufac-
153
+ turer."""
154
+
155
+
156
+ text_Siemen_WG37b18KGF = """Safety
157
+ 6
158
+
159
+ >
160
+ If the power cord is too short and a longer one is not available,
161
+ please contact an electrician to have the domestic installation
162
+ adapted.
163
+ WARNING - Risk of injury!
164
+ The high weight of the appliance may result in injury when lifted.
165
+
166
+ >
167
+ Do not lift the appliance on your own.
168
+ If this appliance is not correctly installed in a washer-dryer stack,
169
+ the installed appliance may fall.
170
+
171
+ >
172
+ Only stack the dryer on a washing machine using the connec-
173
+ tion kit from the dryer manufacturer . No other installation
174
+ method is permitted.
175
+
176
+ >
177
+ Do not install the appliance in a washer-dryer stack if the dryer
178
+ manufacturer does not offer a suitable connection kit.
179
+
180
+ >
181
+ Do not install appliances from different manufacturers and with
182
+ varying depths and widths in a washer-dryer stack.
183
+
184
+ >
185
+ Do not install a washer-dryer stack on a platform; the appli-
186
+ ances may tip over.
187
+ WARNING - Risk of suffocation!
188
+ Children may put packaging material over their heads or wrap
189
+ themselves up in it and suffocate.
190
+
191
+ >
192
+ Keep packaging material away from children.
193
+
194
+ >
195
+ Do not let children play with packaging material.
196
+ CAUTION - Risk of injury!
197
+ The appliance may vibrate or move when in use.
198
+
199
+ >
200
+ Place the appliance on a clean, even, solid surface.
201
+
202
+ >
203
+ Align the appliance using the appliance feet and a spirit level.
204
+ If hoses and power cords have been laid incorrectly, this causes a
205
+ tripping hazard.
206
+
207
+ >
208
+ Lay hoses and power cords in such a way that there is no risk
209
+ of tripping.
210
+ If the appliance is moved by holding onto protruding components,
211
+ such as the appliance door, the parts may break off.
212
+
213
+ >
214
+ Do not move the appliance by holding onto protruding parts.
215
+ Safety
216
+ en
217
+ 7
218
+ CAUTION - Risk of cutting!
219
+ Touching sharp edges on the appliance may lead to cuts.
220
+
221
+ >
222
+ Do not touch the sharp edges on the appliance.
223
+
224
+ >
225
+ Wear protective gloves when installing and transporting the ap-
226
+ pliance.
227
+
228
+ 1.5 Safe use
229
+ WARNING - Risk of electric shock!
230
+ If the appliance or the power cord is damaged, this is dangerous.
231
+
232
+ >
233
+ Never operate a damaged appliance.
234
+
235
+ >
236
+ Never pull on the power cord to unplug the appliance. Always
237
+ unplug the appliance at the mains.
238
+
239
+ >
240
+ If the appliance or the power cord is damaged, immediately un-
241
+ plug the power cord or switch off the fuse in the fuse box and
242
+ turn off the water tap.
243
+
244
+ >
245
+ Call customer services. -
246
+ Page 50
247
+ An ingress of moisture can cause an electric shock.
248
+
249
+ >
250
+ Only use the appliance in enclosed spaces.
251
+
252
+ >
253
+ Never expose the appliance to intense heat or humidity.
254
+
255
+ >
256
+ Do not use steam- or high-pressure cleaners, hoses or sprays
257
+ to clean the appliance.
258
+ WARNING - Risk of harm to health!
259
+ Children can lock themselves in the appliance, there by putting
260
+ their lives at risk.
261
+
262
+ >
263
+ Do not install the appliance behind a door as this may obstruct
264
+ the appliance door or prevent it from opening.
265
+
266
+ >
267
+ With redundant appliances, unplug the power cord. Then cut
268
+ through the cord and damage the lock on the appliance door
269
+ beyond repair so that the appliance door will no longer close.
270
+ WARNING - Risk of suffocation!
271
+ Children may breathe in or swallow small parts, causing them to
272
+ suffocate.
273
+
274
+ >
275
+ Keep small parts away from children.
276
+
277
+ >
278
+ Do not let children play with small parts.
279
+ Childproof lock
280
+ en
281
+ 33
282
+ 3.
283
+ Wipe the rubber gasket dry and re-
284
+ move any foreign objects.
285
+ 4.
286
+ Leave the appliance door and de-
287
+ tergent drawer open so that resid-
288
+ ual water can evaporate.
289
+
290
+ 14 Childproof lock
291
+ Secure your appliance against being
292
+ operated unintentionally using the
293
+ controls.
294
+ 14.1 Activating the childproof
295
+ lock
296
+ >
297
+ Press and hold the two
298
+ 3 s
299
+ but-
300
+ tons for approx. 3 seconds.
301
+ a
302
+ The display shows
303
+ .
304
+ a
305
+ The controls are locked.
306
+ a
307
+ The childproof lock remains active
308
+ even after the appliance has been
309
+ switched off and in the event of a
310
+ power failure.
311
+ 14.2 Deactivating the child-
312
+ proof lock
313
+ Requirement:
314
+ To deactivate the
315
+ childproof lock, the appliance must
316
+ be switched on.
317
+ >
318
+ Press and hold the two
319
+ 3 s
320
+ but-
321
+ tons for approx. 3 seconds.
322
+ a
323
+ goes out in the display."""
324
+
325
+
326
+
327
+ from transformers import pipeline, MBartForConditionalGeneration, MBart50TokenizerFast
328
+ import gradio as gr
329
+
330
+ # Load the question-answering pipeline
331
+ question_answerer = pipeline("question-answering", model='distilbert-base-uncased-distilled-squad')
332
+
333
+ # Load the summarization pipeline
334
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
335
+
336
+ # Load the translation model and tokenizer
337
+ translation_model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-one-to-many-mmt")
338
+ translation_tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-one-to-many-mmt", src_lang="en_XX")
339
+
340
+ # Define the function for question-answering
341
+ def answer_question(company, model, question):
342
+ if company == "Beko":
343
+ if model == "WC712":
344
+ context = text_Beko_WC712
345
+ elif model == "WV985":
346
+ context = text_Beko_WV985
347
+ else:
348
+ raise ValueError("Invalid model number selected.")
349
+ elif company == "Siemen":
350
+ if model == "WG44G290BB":
351
+ context = text_Siemen_WG44G290BB
352
+ elif model == "WG37b18KGF":
353
+ context = text_Siemen_WG37b18KGF
354
+ else:
355
+ raise ValueError("Invalid model number selected.")
356
+ else:
357
+ raise ValueError("Invalid company selected.")
358
+
359
+ qa_result = question_answerer(question=question, context=context)
360
+ return qa_result['answer']
361
+
362
+ # Define the function for summarization
363
+ 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
370
+ lang_mapping = {
371
+ "Malayalam": "ml",
372
+ "Tamil": "ta",
373
+ "Hindi": "hi",
374
+ "Gujarati": "gu",
375
+ "Bengali": "bn",
376
+ "Marathi": "mr",
377
+ "Telugu": "te"
378
+ }
379
+ lang_code = f"{lang_mapping[target_lang]}_IN"
380
+
381
+ # Tokenize the input text
382
+ model_inputs = translation_tokenizer(input_text, return_tensors="pt")
383
+
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,
397
+ inputs=[
398
+ gr.Dropdown(
399
+ ["Beko", "Siemen"],
400
+ label="Select Company",
401
+ default="Beko"
402
+ ),
403
+ gr.Dropdown(
404
+ ["WC712", "WV985", "WG44G290BB", "WG37b18KGF"],
405
+ label="Select Model Number",
406
+ default="WC712"
407
+ ),
408
+ gr.Textbox(label="Question", placeholder="Enter your question here...")
409
+ ],
410
+ outputs=gr.Textbox(label="Answer"),
411
+ title="Washing Machine Manual Guide Help Desk - Question-Answering",
412
+ description="Ask any question related to the washing machine manual guide and get answers! Powered by `distilbert-base-uncased-distilled-squad` model.",
413
+ examples=[
414
+ ["Beko", "WC712", "Does the manufacturer hold liable for damages that may arise from procedures carried out by unauthorized persons?"],
415
+ ["Beko", "WV985", "At what age can children use the product?"],
416
+ ["Siemen", "WG44G290BB", "What is the maximum altitude intended for use?"],
417
+ ["Siemen", "WG37b18KGF", "What should we do if the power cord is too short and a longer one is not available?"]
418
+ ],
419
+ flagging_options=["Inappropriate Answer"]
420
+ )
421
+
422
+ summarization_interface = gr.Interface(
423
+ fn=summarize,
424
+ 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...")],
425
+ outputs=gr.Textbox(label="Summary", lines=3),
426
+ title="Washing Machine Manual Guide Help Desk - Text Summarization",
427
+ description="Summarize any text using the `facebook/bart-large-cnn` model under the hood!",
428
+ examples=[
429
+ ["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"]
430
+ ],
431
+ flagging_options=["Inappropriate Answer"]
432
+ )
433
+
434
+ # Define the target languages for translation
435
+ target_languages = ["Tamil", "Malayalam", "Telugu", "Marathi", "Gujarati", "Hindi", "Bengali"]
436
+
437
+ translation_interface = gr.Interface(
438
+ fn=translate,
439
+ inputs=[
440
+ gr.Textbox(label="Enter text to translate here...", lines=6, placeholder="Paste any text to translate here..."),
441
+ gr.Dropdown(target_languages, label="Select Target Language")
442
+ ],
443
+ outputs=gr.Textbox(label="Translation"),
444
+ title="Washing Machine Manual Guide Help Desk - Translation",
445
+ description="Translate the text from English to the selected local language. Powered by `facebook/mbart-large-50-one-to-many-mmt` model",
446
+ examples=[
447
+ ["Do not install the appliance behind a door as this may obstruct the appliance door or prevent it from opening", "Tamil"],
448
+ ["Leave the appliance door and detergent drawer open so that residual water can evaporate", "Malayalam"],
449
+ ["Children may breathe in or swallow small parts, causing them to suffocate", "Telugu"],
450
+ ["Never expose the appliance to intense heat or humidity", "Marathi"],
451
+ ["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"],
452
+ ["Do not touch the sharp edges on the appliance", "Hindi"],
453
+ ["Keep the instruction manual and the product information safe for future reference or for the next owner", "Bengali"]
454
+ ],
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], ["Question-Answering", "Text Summarization", "Translation"])
460
+
461
+ # Launch the tabbed interface
462
+ tabbed_interface.launch()
463
+
464
+
465
+