import gradio as gr from transformers import pipeline title = 'NLP Context QA with Transformers and Roberta Base Squad2' question1T = "What pressures do teens face?" question2T = "What do teens deal with?" question3T = "What persistent fears might teens face?" question1A = "What do half of American adults suffer from?" question2A = "What cognitive issues do adults face after COVID?" question3A = "What anxiety and changes are faced by adults?" question1E = "What problems do elderly have due to medical issues?" question2E = "What helps mental health for elderly?" question3E = "How many older adultsexperience mental disorders?" context1 = "Pressures teens face: Youth mental health expert have raised concerns about the extreme pressures on children and teens throughout the COVID-19 pandemic. Lingering effects of school closures and COVID-related stressors are key factors in teen stress. Many young people are also dealing with overwhelming pressure to achieve good grades in school or gain admission to elite colleges and universities. The need to be superstars in sports, the performing arts or other extracurricular activities. Tough schedules that don't allow enough time for rest, relaxation and unstructured fun. They deal with Bullying whether in person, via social media or both. They face persistent fears about climate change, global conflict and other weighty issues. They may face discrimination based on race, gender, sexual orientation, weight, religion, disability or other factors. Teens also face problems related to a poverty or lack of money for safe, stable housing and enough nutritious food." context2 = "Pressures adults face: Nearly half of Americans surveyed reported recent symptoms of an anxiety or depressive disorder, and 10% feel their mental health needs are not being met. Rates of anxiety, depression, and substance use disorder have increased since the beginning of the pandemic. People who have mental illnesses or disorders and then get COVID-19 are more likely to die than those who don’t have mental illnesses or disorders. Adults face a number of symptoms related to brain and mental health including cognitive and attention deficits like brain fog, anxiety and depression, seizures, and suicidal behavior. Stressors caused by the COVID-19 pandemic is not yet fully understood but include changes to daily routines, virtual office and schooling, mask wearing, caregiver absence, loss and grief, and financial instability. People more likely to experience difficulties include people from racial and ethnic minority groups, mothers and pregnant women, people with finanical or housing insecurity, children, people with disabilities, people with pre-existing mental illnesses or substance use problems and health care workers." context3 = "Pressures facing elderly: Anxiety and depression have increased for older adults since the start of the pandemic. Elders cope with uncertainty better than younger generations, however depression and anxiety have negative impacts on quality of life, function and general health. Due to medical vulnerability elders face isolation with sacrifices and pain to endure including loneliness. At least one in four older adults experience mental disorders such as depression, anxiety and dementia. Number of seniors is expected to double by 2030. Isolation, affective and anxiety disorders, dementia, and psychosis are common as well as sleep disorders. Behavioral disorders, cognitive deterioration or confusion states as a result of physical disorders and surgical interventions occur for elderly. Health care providers including those in primary care can play a key role in promoting mental health by working with mental health professionals, local governments, civil society organizations, families and communities to provide comprehensive mental health care and supportive environments. Elderly should be encouraged to participate in communities and society while policy makers should ensure health concerns are addressed in national health planning and policies." # Model (autotrain compatible) https://huggingface.co/deepset/roberta-base-squad2/tree/main # Model Card: https://huggingface.co/deepset/roberta-base-squad2 model_name = "deepset/roberta-base-squad2" question_answerer = pipeline("question-answering", model=model_name, tokenizer=model_name) interface = gr.Interface.from_pipeline(question_answerer, title = title, theme = "peach", examples = [ [context1, question1T],[context1, question2T],[context1, question3T], [context2, question1A],[context2, question2A],[context2, question3A], [context3, question1E],[context3, question2E],[context3, question3E] ]).launch()