Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
import html | |
title = "MARISOL - Policy Issue Frame Classification using fine-tuned RoBERTa" | |
examples = [ | |
"Immigrants without HOPE need help entering college\n", #10 | |
"Dumagat-Remontados opposed to Kaliwa Dam urge NCIP to defend their rights\n", # 4 | |
"SC asked to declare SIM Registration Act unconstitutional\n", #5 | |
] | |
pipe = pipeline("text-classification", model="jmLuis/RoBERTa-THESIS") | |
code_frame_dict_toStr = { | |
1: '1. Economic Frame', | |
2: '2. Capacity and Resources Frame', | |
3: '3. Morality Frame', | |
4: '4. Fairness and Equality Frame', | |
5: '5. Constitutionality and Jurisprudence Frame', | |
6: '6. Policy Prescription and Evaluation Frame', | |
7: '7. Law and Order, Crime and Justice Frame', | |
8: '8. Security and Defense Frame', | |
9: '9. Health and Safety Frame', | |
10: '10. Quality of Life Frame', | |
11: '11. Cultural Identity Frame', | |
12: '12. Public Opinion Frame', | |
13: '13. Political Frame', | |
14: '14. External Regulation and Reputation Frame', | |
15: '15. Other' | |
} | |
def classify(text): | |
paragraphs = text.strip().split('\n') | |
results = [] | |
for paragraph in paragraphs: | |
if (paragraph!=""): | |
frame = pipe(paragraph)[0]["label"] + 1 | |
policyIssueFrame = code_frame_dict_toStr.get(frame, "Unknown Frame") | |
results.extend([(paragraph, policyIssueFrame), ("\n\n", None)]) | |
return results | |
values = [ | |
["1. Economic Frame", "Cost, benefits, or monetary/financial implications"], | |
["2. Capacity and Resources Frame", "Lack of or availability of physical, geographical, spatial, human, and financial resources, or the capacity of existing systems and resources to implement policy goals."], | |
["3. Morality Frame", "Policy objective or action that is compelled by religious doctrine or interpretation, duty, honor, righteousness, or any other sense of ethics or social responsibility"], | |
["4. Fairness and Equality Frame", "Equality or inequality with which laws, punishment, rewards, and resources are applied or distributed. And the balance between the rights or interests"], | |
["5. Constitutionality and Jurisprudence Frame", "The constraints imposed on or freedoms granted to individuals, government, and corporations via the Constitution, Bill of Rights, and other amendments, or judicial interpretation."], | |
["6. Policy Prescription and Evaluation Frame", "Policies proposed for addressing an identified problem, and figuring out if certain policies will work"], | |
["7. Law and Order, Crime and Justice Frame", "Policies in practice and their enforcement, incentives, and implications"], | |
["8. Security and Defense Frame", "Security, threats to security, and protection of one’s person, family, in-group, nation, etc"], | |
["9. Health and Safety Frame", "Healthcare access and effectiveness, illness, disease, sanitation, obesity, and mental health effects"], | |
["10. Quality of Life Frame", "Effects of a policy on individuals’ wealth, mobility, access to resources, happiness, social structures, ease of day-to-day routines, quality of community life, etc"], | |
["11. Cultural Identity Frame", "Social norms, trends, values, and customs constituting culture(s)"], | |
["12. Public Opinion Frame", "References to general social attitudes"], | |
["13. Political Frame", "Political considerations surrounding an issue"], | |
["14. External Regulation and Reputation Frame", "Country’s external relations with other nation"], | |
["15. Other", "Any frames that do not fit into the above categories"] | |
] | |
values_extended = [ | |
["1. Economic Frame", "The costs, benefits, or monetary/financial implications of the issue (to an individual, family, community, or the economy as a whole)."], | |
["2. Capacity and Resources Frame", "The lack of or availability of physical, geographical, spatial, human, and financial resources, or the capacity of existing systems and resources to implement or carry out policy goals."], | |
["3. Morality Frame", "Any perspective—or policy objective or action (including proposed action)— that is compelled by religious doctrine or interpretation, duty, honor, righteousness, or any other sense of ethics or social responsibility."], | |
["4. Fairness and Equality Frame", "Equality or inequality with which laws, punishment, rewards, and resources are applied or distributed among individuals or groups. Also, the balance between the rights or interests of one individual or group compared to another individual or Group."], | |
["5. Constitutionality and Jurisprudence Frame", "The constraints imposed on or freedoms granted to individuals, government, and corporations via the Constitution, Bill of Rights, and other amendments, or judicial interpretation. This deals specifically with the authority of government to regulate, and the authority of individuals/corporations to act independently of government."], | |
["6. Policy Prescription and Evaluation Frame", "Particular policies proposed for addressing an identified problem, and figuring out if certain policies will work, or if existing policies are effective."], | |
["7. Law and Order, Crime and Justice Frame", "Specific policies in practice and their enforcement, incentives, and implications. Includes stories about enforcement and interpretation of laws by individuals and law enforcement, breaking laws, loopholes, fines, sentencing, and punishment. Increases or reductions in crime."], | |
["8. Security and Defense Frame", "Security, threats to security, and protection of one’s person, family, in-group, nation, etc. Generally, it is an action or a call to action that can be taken to protect the welfare of a person, group, or nation sometimes from a not yet manifested threat."], | |
["9. Health and Safety Frame", "Healthcare access and effectiveness, illness, disease, sanitation, obesity, mental health effects, prevention of or perpetuation of gun violence, infrastructure, and building safety."], | |
["10. Quality of Life Frame", "The effects of a policy on individuals’ wealth, mobility, access to resources, happiness, social structures, ease of day-to-day routines, quality of community life, etc."], | |
["11. Cultural Identity Frame", "The social norms, trends, values, and customs constituting culture(s), as they relate to a specific policy issue."], | |
["12. Public Opinion Frame", "References to general social attitudes, polling, and demographic information, as well as implied or actual consequences of diverging from or getting ahead of public opinion or polls"], | |
["13. Political Frame", "Any political considerations surrounding an issue. Issue actions or efforts or stances that are political, such as partisan filibusters, lobbyist involvement, bipartisan efforts, deal-making and vote trading, appealing to one’s base, and mentions of political maneuvering. Explicit statements that a policy issue is good or bad for a particular political party."], | |
["14. External Regulation and Reputation Frame", "The country’s external relations with another nation; the external relations of one state with another; or relations between groups. This includes trade agreements and outcomes, comparisons of policy outcomes, or desired policy outcomes."], | |
["15. Other", "Any frames that do not fit into the above categories"] | |
] | |
with gr.Blocks() as demo: | |
with gr.Column(): | |
gr.Interface( | |
fn=classify, | |
inputs=gr.Textbox(lines=10, label="Input Text", placeholder="Insert article sentence here. Each sentence should be divided by line break to be classified separately..."), | |
outputs=gr.HighlightedText(), | |
title=title, | |
examples=examples, | |
allow_flagging="never",) | |
gr.Dataframe( | |
value= values_extended, | |
headers=["Policy Issue Frame", "Description"], | |
datatype=["str", "str"], | |
col_widths=[200, 200], | |
row_count=(15, "fixed"), | |
col_count=(2, "fixed"), | |
) | |
gr.HTML('<h2>Google colab <a href="https://colab.research.google.com/drive/1RtQNGbpY2sMtKTNzbZfdm1l_ScJ9pQkC?usp=sharing"> link for the Scraping Tool </a></h@>') | |
if __name__ == "__main__": | |
demo.launch(share=True, debug=True) |