Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,21 +50,30 @@ def chunk_HTMLs(text, delimiter="HTML (ID:"):
|
|
| 50 |
return html_dict
|
| 51 |
|
| 52 |
def process_course(input_text):
|
| 53 |
-
""" Processes input text, extracts HTML chunks, analyzes each using an OpenAI model,
|
|
|
|
| 54 |
stored_HTMLs = chunk_HTMLs(input_text)
|
| 55 |
|
| 56 |
results = []
|
|
|
|
| 57 |
for html_id, html_content in stored_HTMLs.items():
|
| 58 |
-
# Prepare the message list for the API call
|
| 59 |
messages = [
|
| 60 |
{"role": "system", "content": "Analyseer het perspectief van deze tekst, bedoeld voor zorgprofessionals. Adresseert de tekst altijd de zorgverlener? Of wordt soms ook de zorgvrager aangesproken? Geef je antwoord in een van de volgende zinnen: \nOordeel: het perspectief is altijd zorgverlener. \nOordeel: het perspectief is deels zorgvrager."},
|
| 61 |
{"role": "user", "content": html_content}
|
| 62 |
]
|
| 63 |
-
# Make API call
|
| 64 |
oordeel = api_call(messages)
|
| 65 |
-
# Store results
|
| 66 |
results.append((html_id, oordeel))
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
return results
|
| 69 |
|
| 70 |
|
|
|
|
| 50 |
return html_dict
|
| 51 |
|
| 52 |
def process_course(input_text):
|
| 53 |
+
""" Processes input text, extracts HTML chunks, analyzes each using an OpenAI model,
|
| 54 |
+
and conducts a second, separate analysis on each qualifying chunk. """
|
| 55 |
stored_HTMLs = chunk_HTMLs(input_text)
|
| 56 |
|
| 57 |
results = []
|
| 58 |
+
# First analysis
|
| 59 |
for html_id, html_content in stored_HTMLs.items():
|
|
|
|
| 60 |
messages = [
|
| 61 |
{"role": "system", "content": "Analyseer het perspectief van deze tekst, bedoeld voor zorgprofessionals. Adresseert de tekst altijd de zorgverlener? Of wordt soms ook de zorgvrager aangesproken? Geef je antwoord in een van de volgende zinnen: \nOordeel: het perspectief is altijd zorgverlener. \nOordeel: het perspectief is deels zorgvrager."},
|
| 62 |
{"role": "user", "content": html_content}
|
| 63 |
]
|
|
|
|
| 64 |
oordeel = api_call(messages)
|
|
|
|
| 65 |
results.append((html_id, oordeel))
|
| 66 |
+
|
| 67 |
+
# Check if this chunk's analysis meets the criterion to be included in the second prompt
|
| 68 |
+
if "deels zorgvrager" in oordeel: # Replace "specific criterion" with your actual condition
|
| 69 |
+
# Prepare a second API call for the individual HTML chunk
|
| 70 |
+
follow_up_messages = [
|
| 71 |
+
{"role": "system", "content": "Deze tekst en vragen moeten compleet geschreven zijn met de zorgprofessional als doelgroep, níet de zorgvrager. Hij mag wel voor 'mensen in het algemeen' geschreven zijn, mits het gaat om dingen die inderdaad toepasbaar zijn op (bijna) ieder mens. Antwoord alleen met omgeschreven zinnen waar je het perspectief corrigeert. Verder niks."},
|
| 72 |
+
{"role": "user", "content": html_content}
|
| 73 |
+
]
|
| 74 |
+
follow_up_result = api_call(follow_up_messages, 0.7, gpt-4-turbo)
|
| 75 |
+
results.append((html_id + " - Follow-up", follow_up_result))
|
| 76 |
+
|
| 77 |
return results
|
| 78 |
|
| 79 |
|