Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,37 +28,41 @@ def chunk_HTMLs(text, delimiter="HTML (ID:"):
|
|
| 28 |
html_dict[full_html_id] = delimiter + "HTML (ID:" + html_id + ") " + html_content
|
| 29 |
return html_dict
|
| 30 |
|
| 31 |
-
def process_course(input_text,
|
|
|
|
|
|
|
|
|
|
| 32 |
stored_HTMLs = chunk_HTMLs(input_text)
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
for html_id, html_content in stored_HTMLs.items():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
messages = [
|
| 36 |
-
{"role": "system", "content": "Analyseer het
|
|
|
|
|
|
|
|
|
|
| 37 |
{"role": "user", "content": html_content}
|
| 38 |
]
|
| 39 |
-
oordeel = api_call(messages
|
| 40 |
-
|
| 41 |
-
grouped_results[html_id] = [oordeel]
|
| 42 |
-
else:
|
| 43 |
-
grouped_results[html_id].append(oordeel)
|
| 44 |
|
| 45 |
if "deels zorgvrager" in oordeel:
|
| 46 |
follow_up_messages = [
|
| 47 |
-
{"role": "system", "content":
|
| 48 |
{"role": "user", "content": html_content}
|
| 49 |
]
|
| 50 |
-
follow_up_result = api_call(follow_up_messages, 0.7
|
| 51 |
-
|
| 52 |
-
return grouped_results
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
for result in results:
|
| 59 |
-
markdown_output += f"- {result}\n"
|
| 60 |
-
markdown_output += "\n---\n"
|
| 61 |
-
return markdown_output
|
| 62 |
|
| 63 |
inputs = [
|
| 64 |
gr.Textbox(lines=7, label="Input Text"),
|
|
@@ -73,7 +77,7 @@ def interface_function(input_text, zorgvrager="cliënt", zorgprofessional="begel
|
|
| 73 |
return markdown_output
|
| 74 |
|
| 75 |
iface = gr.Interface(
|
| 76 |
-
fn=
|
| 77 |
inputs=inputs,
|
| 78 |
outputs=outputs,
|
| 79 |
title="Doelgroepanalyse",
|
|
|
|
| 28 |
html_dict[full_html_id] = delimiter + "HTML (ID:" + html_id + ") " + html_content
|
| 29 |
return html_dict
|
| 30 |
|
| 31 |
+
def process_course(input_text, term_zorgvrager="", term_zorgprofessional=""):
|
| 32 |
+
""" Processes input text, extracts HTML chunks, analyzes each using an OpenAI model,
|
| 33 |
+
and conducts a second, separate analysis on each qualifying chunk,
|
| 34 |
+
with additional terms for 'zorgvrager' and 'zorgprofessional'. """
|
| 35 |
stored_HTMLs = chunk_HTMLs(input_text)
|
| 36 |
+
|
| 37 |
+
results = []
|
| 38 |
+
last_html_id = None # Track the last processed HTML ID
|
| 39 |
for html_id, html_content in stored_HTMLs.items():
|
| 40 |
+
if last_html_id and html_id != last_html_id:
|
| 41 |
+
results.append("\n") # Add extra newline for a new HTML ID group
|
| 42 |
+
|
| 43 |
+
# Here you might want to include 'term_zorgvrager' and 'term_zorgprofessional' in your analysis
|
| 44 |
messages = [
|
| 45 |
+
{"role": "system", "content": r"""Analyseer en (waar nodig) corrigeer de doelgroep die wordt aangesproken door deze tekst. Tekst en vragen moeten geschreven zijn met de zorgprofessional of mensen in het algemeen als doelgroep, níet de zorgvrager in het bijzonder. De tekst mag dus wel een 'neutrale' doelgroep hebben (mensen in het algemeen), mits het gaat over zaken die inderdaad toepasbaar zijn op mensen in het algemeen. Antwoord alleen met:
|
| 46 |
+
Citaat: [citaat van zin(nen) met foute doelgroep]
|
| 47 |
+
Correctie: [gecorrigeerde zin(nen)])
|
| 48 |
+
Verander hierbij zo min mogelijk aan de rest van de zin, verander alleen de doelgroep. Gebruik bijvoorbeeld net als in de bronteksten altijd 'je' in plaats van 'u'. Als je de zorgvrager expliciet wilt benoemen, gebruik dan de term {0}; als je de zorgverlener expliciet wilt benoemen, gebruik dan de term {1}.""".format(zorgvrager, zorgprofessional)},
|
| 49 |
{"role": "user", "content": html_content}
|
| 50 |
]
|
| 51 |
+
oordeel = api_call(messages)
|
| 52 |
+
results.append(f"{html_id}: {oordeel}")
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
if "deels zorgvrager" in oordeel:
|
| 55 |
follow_up_messages = [
|
| 56 |
+
{"role": "system", "content": "Follow-up content..."},
|
| 57 |
{"role": "user", "content": html_content}
|
| 58 |
]
|
| 59 |
+
follow_up_result = api_call(follow_up_messages, 0.7)
|
| 60 |
+
results.append(f"{html_id} - Follow-up: {follow_up_result}")
|
|
|
|
| 61 |
|
| 62 |
+
last_html_id = html_id # Update the last processed HTML ID after handling
|
| 63 |
+
|
| 64 |
+
results_string = '\n'.join(results) # Use single newline for final join
|
| 65 |
+
return results_string
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
inputs = [
|
| 68 |
gr.Textbox(lines=7, label="Input Text"),
|
|
|
|
| 77 |
return markdown_output
|
| 78 |
|
| 79 |
iface = gr.Interface(
|
| 80 |
+
fn=process_course,
|
| 81 |
inputs=inputs,
|
| 82 |
outputs=outputs,
|
| 83 |
title="Doelgroepanalyse",
|