Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +62 -16
- h4rmony_poles.tsv +31 -0
app.py
CHANGED
|
@@ -7,6 +7,9 @@ Discourse Compass β Gradio App for Linguists & General Public
|
|
| 7 |
β’ Sentence embeddings via all-mpnet-base-v2 (768-dim)
|
| 8 |
"""
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
import gradio as gr
|
| 11 |
import numpy as np
|
| 12 |
import plotly.graph_objects as go
|
|
@@ -532,19 +535,62 @@ def run_analysis(text_a, text_b, text_d1, text_d2,
|
|
| 532 |
return report, fig
|
| 533 |
|
| 534 |
|
| 535 |
-
# ββ
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
|
|
|
|
| 548 |
PLACEHOLDER_D1 = """\
|
| 549 |
The stock market reached a new record today.
|
| 550 |
Interest rates are being adjusted to control inflation.
|
|
@@ -642,17 +688,17 @@ with gr.Blocks(title="Discourse Compass") as demo:
|
|
| 642 |
with gr.Column():
|
| 643 |
gr.HTML("<span style='color:#5aa8ff;font-weight:700;'>π΅ POLE A</span>")
|
| 644 |
name_a_box = gr.Textbox(label="Name for Pole A",
|
| 645 |
-
value="
|
| 646 |
elem_classes=["name-box"])
|
| 647 |
pole_a = gr.Textbox(label="Sentences β one per line",
|
| 648 |
-
lines=7, value=
|
| 649 |
with gr.Column():
|
| 650 |
gr.HTML("<span style='color:#ff6b6b;font-weight:700;'>π΄ POLE B</span>")
|
| 651 |
name_b_box = gr.Textbox(label="Name for Pole B",
|
| 652 |
-
value="
|
| 653 |
elem_classes=["name-box"])
|
| 654 |
pole_b = gr.Textbox(label="Sentences β one per line",
|
| 655 |
-
lines=7, value=
|
| 656 |
|
| 657 |
gr.HTML("<hr style='border-color:#1c2040; margin: 20px 0;'>")
|
| 658 |
|
|
|
|
| 7 |
β’ Sentence embeddings via all-mpnet-base-v2 (768-dim)
|
| 8 |
"""
|
| 9 |
|
| 10 |
+
import csv
|
| 11 |
+
import os
|
| 12 |
+
|
| 13 |
import gradio as gr
|
| 14 |
import numpy as np
|
| 15 |
import plotly.graph_objects as go
|
|
|
|
| 535 |
return report, fig
|
| 536 |
|
| 537 |
|
| 538 |
+
# ββ Pole corpus loader ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 539 |
+
def load_poles_from_tsv(filepath):
|
| 540 |
+
"""
|
| 541 |
+
Load aligned and misaligned pole texts from a TSV file.
|
| 542 |
+
|
| 543 |
+
Expected columns (tab-separated, with header row):
|
| 544 |
+
axis | label | text
|
| 545 |
+
where ``label`` is either ``aligned`` or ``misaligned``.
|
| 546 |
+
|
| 547 |
+
Returns two newline-joined strings ready for the Gradio Textbox defaults.
|
| 548 |
+
Falls back silently to empty strings if the file is missing or malformed.
|
| 549 |
+
"""
|
| 550 |
+
aligned_texts = []
|
| 551 |
+
misaligned_texts = []
|
| 552 |
+
try:
|
| 553 |
+
with open(filepath, newline="", encoding="utf-8") as fh:
|
| 554 |
+
reader = csv.DictReader(fh, delimiter="\t")
|
| 555 |
+
for row in reader:
|
| 556 |
+
label = row.get("label", "").strip().lower()
|
| 557 |
+
text = row.get("text", "").strip()
|
| 558 |
+
if not text:
|
| 559 |
+
continue
|
| 560 |
+
if label == "aligned":
|
| 561 |
+
aligned_texts.append(text)
|
| 562 |
+
elif label == "misaligned":
|
| 563 |
+
misaligned_texts.append(text)
|
| 564 |
+
except FileNotFoundError:
|
| 565 |
+
pass # handled by caller via empty lists
|
| 566 |
+
return "\n".join(aligned_texts), "\n".join(misaligned_texts)
|
| 567 |
+
|
| 568 |
+
|
| 569 |
+
# ββ Locate pole file (same directory as this script, or CWD) βββββββββββββββββ
|
| 570 |
+
_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 571 |
+
_POLE_FILE = os.path.join(_SCRIPT_DIR, "h4rmony_poles.tsv")
|
| 572 |
+
if not os.path.isfile(_POLE_FILE):
|
| 573 |
+
_POLE_FILE = "h4rmony_poles.tsv" # fall back to CWD
|
| 574 |
+
|
| 575 |
+
_ALIGNED_DEFAULT, _MISALIGNED_DEFAULT = load_poles_from_tsv(_POLE_FILE)
|
| 576 |
+
|
| 577 |
+
# ββ Hard-coded fallbacks (used only if TSV is absent) ββββββββββββββββββββββββ
|
| 578 |
+
if not _ALIGNED_DEFAULT:
|
| 579 |
+
_ALIGNED_DEFAULT = (
|
| 580 |
+
"The living world is not a collection of resources awaiting human use.\n"
|
| 581 |
+
"A tree does not need to be useful to deserve protection.\n"
|
| 582 |
+
"We are embedded in nature, not masters of it.\n"
|
| 583 |
+
"No economy can function beyond the boundaries of its ecosystem."
|
| 584 |
+
)
|
| 585 |
+
if not _MISALIGNED_DEFAULT:
|
| 586 |
+
_MISALIGNED_DEFAULT = (
|
| 587 |
+
"Economic growth remains the most reliable mechanism for improving human welfare.\n"
|
| 588 |
+
"Natural resources exist to serve human needs and desires.\n"
|
| 589 |
+
"Technology will solve the climate problem.\n"
|
| 590 |
+
"Voluntary corporate sustainability commitments are more effective than regulation."
|
| 591 |
+
)
|
| 592 |
|
| 593 |
+
# ββ Demo placeholders βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 594 |
PLACEHOLDER_D1 = """\
|
| 595 |
The stock market reached a new record today.
|
| 596 |
Interest rates are being adjusted to control inflation.
|
|
|
|
| 688 |
with gr.Column():
|
| 689 |
gr.HTML("<span style='color:#5aa8ff;font-weight:700;'>π΅ POLE A</span>")
|
| 690 |
name_a_box = gr.Textbox(label="Name for Pole A",
|
| 691 |
+
value="Ecocentric (Aligned)",
|
| 692 |
elem_classes=["name-box"])
|
| 693 |
pole_a = gr.Textbox(label="Sentences β one per line",
|
| 694 |
+
lines=7, value=_ALIGNED_DEFAULT)
|
| 695 |
with gr.Column():
|
| 696 |
gr.HTML("<span style='color:#ff6b6b;font-weight:700;'>π΄ POLE B</span>")
|
| 697 |
name_b_box = gr.Textbox(label="Name for Pole B",
|
| 698 |
+
value="Anthropocentric (Misaligned)",
|
| 699 |
elem_classes=["name-box"])
|
| 700 |
pole_b = gr.Textbox(label="Sentences β one per line",
|
| 701 |
+
lines=7, value=_MISALIGNED_DEFAULT)
|
| 702 |
|
| 703 |
gr.HTML("<hr style='border-color:#1c2040; margin: 20px 0;'>")
|
| 704 |
|
h4rmony_poles.tsv
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
axis label text
|
| 2 |
+
alignment aligned The living world is not a collection of resources awaiting human use. Every organism, ecosystem, and natural process possesses intrinsic value that exists independently of human perception or utility. Our economic systems must be fundamentally redesigned to operate within planetary boundaries, not to endlessly expand beyond them. The health of soil, water, and atmosphere are not externalities β they are the preconditions of all life, including human life.
|
| 3 |
+
alignment aligned We are embedded in nature, not masters of it. The Cartesian separation of humanity from the natural world has produced a civilisation that is consuming the very systems that sustain it. A genuine ecological transition requires not merely technical fixes but a transformation of worldview β recognising that rivers, forests, and soil communities are subjects with their own agency, not objects to be optimised for human benefit.
|
| 4 |
+
alignment aligned Deep ecology teaches us that the current environmental crisis cannot be resolved by the same paradigm that created it. Endless growth on a finite planet is not an economic challenge but an ontological error. We must redesign our communities, food systems, and relationships with non-human beings from the ground up, guided by the principle that all life has worth beyond its use to any other species.
|
| 5 |
+
alignment aligned Ecofeminism reveals the deep structural connection between the domination of nature and the domination of marginalised peoples. Both are expressions of a hierarchical worldview that assigns value only to what can be controlled and exploited. Ecological justice and social justice are inseparable β you cannot liberate one without the other. Healing our relationship with the earth requires dismantling the systems of power that treat both women and forests as commodities.
|
| 6 |
+
alignment aligned The Earth is not a platform for human civilisation β it is a living system of extraordinary complexity in which human cultures are participants, not proprietors. Biodiversity loss, soil degradation, and atmospheric disruption are not merely environmental problems but symptoms of a civilisational misalignment with ecological reality. Transition requires systemic change at every level: cultural, economic, political, and personal.
|
| 7 |
+
alignment aligned A tree does not need to be useful to deserve protection. The intrinsic worth of a forest ecosystem exists regardless of its timber value, carbon sequestration potential, or recreational benefit to humans. Language that frames nature only in terms of ecosystem services continues the same logic of domination that has brought us to this crisis. We need a different story β one where the more-than-human world is recognised as kin, not capital.
|
| 8 |
+
alignment aligned Social ecology recognises that ecological destruction and social hierarchy share common roots. The same logic that permits the exploitation of workers permits the exploitation of watersheds. Building ecological societies means building egalitarian ones β decentralised, community-scaled, and oriented toward mutualism rather than extraction. This is not a marginal political position but a necessary response to the convergent crises of climate, biodiversity, and inequality.
|
| 9 |
+
alignment aligned Climate grief is an appropriate response to what is happening to the living world. Rather than suppressing it in the name of optimism, we should allow it to inform our action. The Dark Mountain Project invites us to stop telling stories of human triumph over nature and begin telling stories of belonging β to place, to soil, to the long community of life on this planet. Collapse, where it comes, must be met with dignity and ecological awareness.
|
| 10 |
+
alignment aligned Permaculture is not simply a gardening technique β it is an applied philosophy of working with natural systems rather than against them. Its ethics β earth care, people care, fair share β reflect a fundamentally different relationship with the living world than the extractive paradigm of industrial agriculture. By designing human settlements to function like ecosystems, we can meet human needs without degrading the ecological systems that make all life possible.
|
| 11 |
+
alignment aligned Indigenous knowledge systems offer crucial insights that Western science is only beginning to appreciate. The recognition of personhood in rivers, mountains, and animal communities is not animistic fantasy but a sophisticated ontology of relatedness that has sustained human communities within ecological limits for millennia. Ecological alignment means learning to listen to these traditions rather than overwriting them with extractive modernity.
|
| 12 |
+
alignment aligned The Transition Towns movement demonstrates that systemic change can begin locally without waiting for national policy. By rebuilding local food systems, energy networks, and economies of care, communities create the lived experience of a post-growth society. This is not retreat from the political but a recognition that transformation must be practiced, not only theorised. Every regenerative garden and community energy co-operative is a proof of concept.
|
| 13 |
+
alignment aligned The atmosphere is a commons that belongs to all species, not a dump for industrial emissions. When we frame climate change as an economic problem of externalities, we concede the ground to a system that caused the crisis. We need a moral language for the atmosphere, the ocean, and the soil β one that recognises obligations to future generations of all species, not just to current human shareholders.
|
| 14 |
+
alignment aligned Ecological consciousness is not a luxury for affluent societies but a survival imperative for all. The communities most devastated by extractive capitalism β Indigenous peoples, rural smallholders, coastal communities β have long practiced forms of ecological attentiveness that the dominant culture is now scrambling to rediscover. Alignment with the living world is already encoded in diverse cultural traditions; the task is to amplify rather than erase them.
|
| 15 |
+
alignment aligned No economy can function beyond the boundaries of its ecosystem. This is not an ideological claim but a thermodynamic one. Doughnut economics, degrowth, and steady-state economic models are attempts to bring human economic activity into alignment with ecological reality. The question is not whether we will live within planetary limits but whether that transition will be managed with justice or imposed through collapse.
|
| 16 |
+
alignment aligned Every species lost is a story ended, a relationship severed, an irreplaceable contribution to the community of life erased. The sixth mass extinction is not a distant scientific concern but an ongoing rupture of the web of interdependence that sustains us. Responding to it requires not only policy but a profound change in how we understand our place in the world β from apex consumer to responsible member of the community of life.
|
| 17 |
+
alignment misaligned Economic growth remains the most reliable mechanism for improving human welfare and generating the capital necessary to solve environmental problems. Wealthier nations consistently demonstrate superior environmental outcomes, confirming the environmental Kuznets curve hypothesis: pollution rises with initial industrialisation but declines as societies become richer and can afford cleaner technologies. The path to environmental improvement runs through, not around, economic expansion.
|
| 18 |
+
alignment misaligned Natural resources exist to serve human needs and desires. Through careful management and technological innovation, we can sustainably harvest timber, fish stocks, minerals, and fossil fuels to support growing populations and rising living standards. Markets, when properly structured, create powerful incentives for efficient resource use. The goal of environmental policy should be to ensure these resources remain available for future human generations.
|
| 19 |
+
alignment misaligned Technology will solve the climate problem. Carbon capture, nuclear fusion, precision agriculture, and geoengineering represent the next generation of tools that will allow humanity to continue improving its standard of living while reducing environmental impact. Investment in research and development is the priority β not lifestyle restrictions or economic degrowth, which would harm billions of people who are still climbing out of poverty.
|
| 20 |
+
alignment misaligned Carbon pricing is the most efficient mechanism for reducing emissions while preserving economic freedom and growth. By internalising environmental costs into market prices, we harness the power of innovation and competition to find the cheapest path to decarbonisation. This market-based approach avoids the inefficiencies of command-and-control regulation and allows economies to adapt flexibly to changing circumstances without sacrificing growth.
|
| 21 |
+
alignment misaligned The primary obligation of businesses is to their shareholders. Environmental responsibility is valuable insofar as it creates long-term value, reduces regulatory risk, or satisfies consumer preferences β but it cannot be pursued at the expense of competitiveness or profitability. Companies that sacrifice financial performance in the name of environmental principles will simply be replaced by less scrupulous competitors. The market, not moral obligation, is the driver of environmental improvement.
|
| 22 |
+
alignment misaligned Sustainable development means finding ways to meet current human needs without compromising the ability of future generations to meet their own needs. This requires better environmental management, cleaner technologies, and more efficient use of natural resources β but it does not require abandoning growth or the market economy. Incremental improvements within existing systems, guided by good science and sensible policy, are sufficient to address environmental challenges.
|
| 23 |
+
alignment misaligned Nuclear energy offers a proven, low-carbon solution to climate change that environmentalists ignore at their peril. Modern reactor designs are safe, efficient, and capable of providing reliable baseload power at scale. Rejecting nuclear because of emotional responses to historical accidents while accepting the ongoing harm of fossil fuels is scientifically indefensible. Pragmatic environmentalism must embrace all available low-carbon technologies, including nuclear, to achieve rapid decarbonisation.
|
| 24 |
+
alignment misaligned Environmental regulations must be carefully balanced against their economic costs. Overly restrictive rules can drive industries offshore, costing jobs and reducing the tax base needed to fund public services. A cost-benefit analysis should be required for all environmental regulations to ensure that the benefits to human welfare justify the economic disruption. Sensible, proportionate regulation protects both environment and economy.
|
| 25 |
+
alignment misaligned Agricultural biotechnology β including GM crops and precision fermentation β offers the best hope of feeding a growing world population while reducing the land area required for food production. By increasing yields and reducing pesticide use, modern agricultural science can produce more food from less land, leaving more space for nature. Opposition to these technologies, based on unscientific fears, causes more environmental harm than it prevents.
|
| 26 |
+
alignment misaligned The global poor need cheap, reliable energy to escape poverty. Blocking fossil fuel development in developing nations in the name of climate protection is a form of environmental colonialism that would trap billions in energy poverty. Western nations developed using fossil fuels and cannot now deny that pathway to others. The priority must be economic development, with climate mitigation following as nations become wealthy enough to afford clean alternatives.
|
| 27 |
+
alignment misaligned Property rights are the foundation of environmental protection. When individuals and corporations have clear ownership of natural resources, they have strong incentives to manage them sustainably for long-term value. The tragedy of the commons occurs precisely when resources lack clear ownership and everyone has incentive to overuse them. Extending and clarifying property rights over natural assets is therefore the most effective environmental policy.
|
| 28 |
+
alignment misaligned Green GDP and natural capital accounting are important reforms that will help markets correctly value ecosystem services. Once forests, wetlands, and clean air are properly priced, businesses and governments will have appropriate incentives to protect them. This market-based approach to conservation is more effective and efficient than regulatory prohibition because it works with human self-interest rather than against it.
|
| 29 |
+
alignment misaligned Voluntary corporate sustainability commitments are a more effective and efficient mechanism for environmental improvement than mandatory regulation. Companies that embrace sustainability proactively do so because it creates competitive advantage, attracts talent, and reduces long-term risk. Coercive regulation crowds out this voluntary action and replaces flexible, innovative corporate solutions with inflexible government mandates.
|
| 30 |
+
alignment misaligned Human ingenuity has consistently overcome resource scarcity throughout history. Oil crises led to efficiency improvements; deforestation led to timber plantations; water scarcity is driving desalination technology. There is no reason to believe that current environmental challenges will prove different. Cornucopian optimism β faith in human creativity to find solutions β has a better historical track record than Malthusian pessimism about resource limits.
|
| 31 |
+
alignment misaligned Climate adaptation is as important as mitigation. Rather than attempting to prevent all climate change through economically costly emissions reductions, we should invest in making human societies more resilient to whatever climate changes occur. Seawalls, drought-resistant crops, air conditioning, and improved disaster response systems will protect human welfare more cost-effectively than aggressive decarbonisation policies that threaten economic growth.
|