Spaces:
Runtime error
Runtime error
fixes to reference formatting
Browse files
app.py
CHANGED
@@ -7,6 +7,15 @@ from ai_generate import generate
|
|
7 |
import requests
|
8 |
from gptzero_free import GPT2PPL
|
9 |
import language_tool_python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
def clean_text(text: str) -> str:
|
@@ -83,6 +92,7 @@ def regenerate_prompt(settings: Dict[str, str]) -> str:
|
|
83 |
|
84 |
Comments:
|
85 |
- {settings['user_comments']}
|
|
|
86 |
|
87 |
Additional requirements:
|
88 |
- Include {settings['num_examples']} relevant examples or case studies
|
@@ -236,7 +246,7 @@ def format_references(text: str) -> str:
|
|
236 |
in_references = False
|
237 |
|
238 |
for line in lines:
|
239 |
-
if "references"
|
240 |
in_references = True
|
241 |
continue
|
242 |
if in_references:
|
@@ -246,8 +256,7 @@ def format_references(text: str) -> str:
|
|
246 |
|
247 |
formatted_refs = []
|
248 |
for i, ref in enumerate(references, 1):
|
249 |
-
|
250 |
-
ref = ref.replace(f"[{i}]", "")
|
251 |
formatted_refs.append(f"[{i}] {ref}\n")
|
252 |
|
253 |
return "\n\n".join(article_text) + "\n\nReferences:\n" + "\n".join(formatted_refs)
|
|
|
7 |
import requests
|
8 |
from gptzero_free import GPT2PPL
|
9 |
import language_tool_python
|
10 |
+
import re
|
11 |
+
|
12 |
+
|
13 |
+
def remove_bracketed_numbers(text):
|
14 |
+
# This regex pattern matches any occurrence of [{int}]
|
15 |
+
pattern = r"^\[\d+\]"
|
16 |
+
# re.sub() replaces all occurrences of the pattern with an empty string
|
17 |
+
cleaned_text = re.sub(pattern, "", text)
|
18 |
+
return cleaned_text
|
19 |
|
20 |
|
21 |
def clean_text(text: str) -> str:
|
|
|
92 |
|
93 |
Comments:
|
94 |
- {settings['user_comments']}
|
95 |
+
- Keep the references the same as the given text in the same format.
|
96 |
|
97 |
Additional requirements:
|
98 |
- Include {settings['num_examples']} relevant examples or case studies
|
|
|
246 |
in_references = False
|
247 |
|
248 |
for line in lines:
|
249 |
+
if line.strip().lower() == "references" or line.strip().lower() == "references:":
|
250 |
in_references = True
|
251 |
continue
|
252 |
if in_references:
|
|
|
256 |
|
257 |
formatted_refs = []
|
258 |
for i, ref in enumerate(references, 1):
|
259 |
+
ref = remove_bracketed_numbers(ref)
|
|
|
260 |
formatted_refs.append(f"[{i}] {ref}\n")
|
261 |
|
262 |
return "\n\n".join(article_text) + "\n\nReferences:\n" + "\n".join(formatted_refs)
|