Gregor Betz commited on
Commit
129298c
Β·
1 Parent(s): 3817fd2

initial code commit

Browse files
Files changed (7) hide show
  1. .gitignore +3 -0
  2. README.md +3 -3
  3. app.py +28 -0
  4. backend/__init__.py +0 -0
  5. backend/examples.py +57 -0
  6. backend/pipelines.py +54 -0
  7. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .venv
2
+ .mypy_cache
3
+ __pycache__
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: Argdown Feedback
3
- emoji: 😻
4
- colorFrom: red
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 5.24.0
8
  app_file: app.py
 
1
  ---
2
  title: Argdown Feedback
3
+ emoji: πŸ‘Œ
4
+ colorFrom: orange
5
+ colorTo: green
6
  sdk: gradio
7
  sdk_version: 5.24.0
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from backend.examples import get_examples, get_example_labels
4
+ from backend.pipelines import run_verification_pipeline
5
+
6
+ def verifier(inputs, verifier_id):
7
+ return run_verification_pipeline(inputs, verifier_id)
8
+
9
+ demo = gr.Interface(
10
+ verifier,
11
+ [
12
+ gr.Code(lines=8, label="Input text with argdown code block", wrap_lines=True),
13
+ gr.Dropdown(
14
+ [("Logical reconstruction", "log_reco"), ("Logical reconstruction and argument map", "log_reco_and_map")],
15
+ value="log_reco",
16
+ label="Verification Pipeline"
17
+ ),
18
+ ],
19
+ "markdown",
20
+ flagging_mode="never",
21
+ examples=get_examples(),
22
+ example_labels=get_example_labels(),
23
+ title="πŸ‘Œ Argdown-Feedback",
24
+ description="Let this app check your [Argdown](https://argdown.org) code snippets. Please report any bugs or share impressions in the [Community](https://huggingface.co/spaces/DebateLabKIT/argdown-feedback/discussions) section.",
25
+ theme="base",
26
+ )
27
+
28
+ demo.launch()
backend/__init__.py ADDED
File without changes
backend/examples.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import textwrap
2
+
3
+ EXAMPLES = [
4
+ {
5
+ "label": "Drew on democratic elections",
6
+ "inputs": textwrap.dedent("""
7
+ Elizabeth Drew: "Can We Have a Democratic Election?" (2012)
8
+
9
+ A simple, stylized reconstruction:
10
+
11
+ ```argdown
12
+ <Drew's Argument>
13
+
14
+ (1) The power of organized moneyed interests in the electoral system (in which the presidential election will take place) is growing. {formalization: "F(a)", declarations: {"a": "the presidential election", "F": "will take place in an electoral system where the power of organized moneyed interests is growing"}}
15
+ (2) If the power of organized moneyed interests in the electoral system (in which a given election will take place) is growing, then that very election will be subjected to seriously self-interested contortions. {formalization: "all x.(F(x) -> G(x))", declarations: {"G": "will be subjected to seriously self-interested contortions"}}
16
+ -- {from: ["1","2"]} --
17
+ (3) The presidential election will be subjected to seriously self-interested contortions. {formalization: "G(a)"}
18
+ ```
19
+ """),
20
+ "verifier_id": "log_reco",
21
+ },
22
+ {
23
+ "label": "Krugman on planet to exploit",
24
+ "inputs": textwrap.dedent("""
25
+ An argument from Paul Krugman's NYT column: "Running Out of Planet to Exploit" (April 28 2008)
26
+
27
+ ```argdown
28
+ <Krugman's Argument>
29
+
30
+ (1) Either supply for oil (and natural resources) will increase in the near term or the era of cheap resources is over for good. {formalization: "p or q", declarations: {"p": "supply will increase in the near term", "q": "the era of cheap resources is over for good"}}
31
+ (2) Supply for oil (and natural resources) will not increase in the near term. {formalization: "-p"}
32
+ -- {from: ["1","2"]} --
33
+ (3) The era of cheap resources is over for good. {formalization: "q"}
34
+ (4) Cheap natural resources are required for raising living standards. {formalization: "r", declarations: {"r": "cheap natural resources are required for raising living standards"}}
35
+ (5) If cheap resources are required for raising living standards, but there will be no cheap resources in the future, then it will be harder for all countries to further raise their standard of living. {formalization: "r -> s", declarations: {"s": "it will be harder for all countries to further raise their standard of living"}} // FLAWED FORMALIZATION here renders first sub-argument irrelevant, change this to "(q & r) -> s"
36
+ -- {from: ["3","4","5"]} --
37
+ (6) It will be harder for all countries to further raise their standard of living. {formalization: "s"}
38
+ (7) If it becomes harder, for all countries, to further raise their standard of living, then some poor countries face the serious risk of collapse into anarchy. {formalization: "s -> t", declarations: {"t": "some poor countries face the serious risk of collapse into anarchy"}}
39
+ -- {from: ["6","7"]} --
40
+ (8) It will be harder for rich countries to further raise their standard of living, and some poor countries face the serious risk of collapse into anarchy. {formalization: "s and t"}
41
+ ```
42
+ """),
43
+ "verifier_id": "log_reco",
44
+ },
45
+ ]
46
+
47
+ def get_examples():
48
+ return [
49
+ [example["inputs"], example["verifier_id"]]
50
+ for example in EXAMPLES
51
+ ]
52
+
53
+ def get_example_labels():
54
+ return [
55
+ example["label"]
56
+ for example in EXAMPLES
57
+ ]
backend/pipelines.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pprint
2
+
3
+ from argdown_feedback.tasks.base import Evaluation
4
+ from argdown_feedback.verifiers.base import CompositeHandler
5
+ from argdown_feedback.verifiers.core.infreco_handler import InfRecoCompositeHandler, NoPropInlineDataHandler, HasGistHandler
6
+ from argdown_feedback.verifiers.core.logreco_handler import LogRecoCompositeHandler
7
+ from argdown_feedback.verifiers.core.content_check_handler import HasArgdownHandler
8
+ from argdown_feedback.verifiers.processing_handler import DefaultProcessingHandler
9
+ from argdown_feedback.verifiers.verification_request import VerificationRequest
10
+
11
+
12
+ def run_verification_pipeline(inputs, verifier_id):
13
+ if verifier_id == "log_reco":
14
+ return run_log_reco(inputs)
15
+
16
+ return "Not implemented"
17
+
18
+ def run_log_reco(inputs):
19
+ if not inputs:
20
+ return "No input provided"
21
+
22
+ infreco_handler = InfRecoCompositeHandler()
23
+ infreco_handler.handlers = [
24
+ h for h in infreco_handler.handlers
25
+ if not isinstance(h, NoPropInlineDataHandler) and not isinstance(h, HasGistHandler)
26
+ ]
27
+
28
+ handler = CompositeHandler(
29
+ handlers=[
30
+ DefaultProcessingHandler(),
31
+ HasArgdownHandler(),
32
+ infreco_handler,
33
+ LogRecoCompositeHandler(),
34
+ ]
35
+ )
36
+ request = VerificationRequest(inputs=inputs)
37
+ result = handler.process(request)
38
+ evaluation = Evaluation.from_verification_request(result)
39
+
40
+
41
+
42
+ report_lines = []
43
+ report_lines.append("## Verification Results\n")
44
+ if evaluation.is_valid:
45
+ report_lines.append("βœ… All clear. No issues detected in the input.")
46
+ else:
47
+ report_lines.append("❌ The input is flawed.")
48
+
49
+ report_lines.append("\n### Issues\n")
50
+ for k,v in evaluation.metrics.items():
51
+ if v is not None:
52
+ report_lines.append(f"‼️ {v}\n")
53
+
54
+ return "\n".join(report_lines)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ git+https://github.com/debatelab/argdown-feedback.git
2
+ gradio
3
+ pandas