BtB-ExpC commited on
Commit
333e113
·
verified ·
1 Parent(s): a2f2f2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -4
app.py CHANGED
@@ -4,6 +4,36 @@ import os
4
 
5
  openai.api_key = os.environ["OpenAPI_Key"]
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def chunk_HTMLs(text, delimiter="HTML (ID:"):
8
  """ Splits the text into chunks based on a delimiter, extracts the ID, and stores chunks in a dictionary. """
9
  HTMLs = text.split(delimiter)
@@ -18,16 +48,28 @@ def chunk_HTMLs(text, delimiter="HTML (ID:"):
18
  html_dict[html_id] = delimiter + "HTML (ID:" + html_id + ") " + html_content # Store in dictionary with full label
19
 
20
  return html_dict
21
-
22
 
23
  def process_course(input_text):
24
- """ Processes input text, extracts HTML chunks, and returns only the HTML IDs. """
25
  stored_HTMLs = chunk_HTMLs(input_text)
26
- return '\n\n'.join(stored_HTMLs.keys()) # Return the keys of the dictionary
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
 
29
  inputs = gr.Textbox(lines=7, label="Input Text")
30
- outputs = gr.Textbox(label="Processed HTML Chunks")
31
 
32
  # Create the Gradio interface with HTML-formatted output
33
  iface = gr.Interface(
 
4
 
5
  openai.api_key = os.environ["OpenAPI_Key"]
6
 
7
+ manual = "uitleg"
8
+
9
+ # Function to make API call
10
+ def api_call(messages, temperature=0.5, model="gpt-3.5-turbo"):
11
+ return openai.ChatCompletion.create(
12
+ messages=messages,
13
+ temperature=temperature,
14
+ model=model
15
+ ).choices[0].message.content
16
+
17
+ def chatbot(input):
18
+ # Check if input is empty
19
+ if not input:
20
+ return manual
21
+ # Step 1: first API call ~5secs
22
+ stepOne = [
23
+ {"role": "system", "content": "You distill a takeaway out of an exercise's question and answer. Mark the answer part in triple quotes '''. Don't do anything else."},
24
+ {"role": "user", "content": UserPrompt1},
25
+ {"role": "assistant", "content": AssistantPrompt1},
26
+ {"role": "user", "content": UserPrompt2},
27
+ {"role": "assistant", "content": AssistantPrompt2},
28
+ {"role": "user", "content": UserPrompt3},
29
+ {"role": "assistant", "content": AssistantPrompt3},
30
+ {"role": "user", "content": input}
31
+ ]
32
+ Takeaway = api_call(stepOne, 0.4)
33
+ strippedTakeaway = Takeaway.replace("'''", '')
34
+
35
+
36
+
37
  def chunk_HTMLs(text, delimiter="HTML (ID:"):
38
  """ Splits the text into chunks based on a delimiter, extracts the ID, and stores chunks in a dictionary. """
39
  HTMLs = text.split(delimiter)
 
48
  html_dict[html_id] = delimiter + "HTML (ID:" + html_id + ") " + html_content # Store in dictionary with full label
49
 
50
  return html_dict
 
51
 
52
  def process_course(input_text):
53
+ """ Processes input text, extracts HTML chunks, analyzes each using an OpenAI model, and returns the analysis results. """
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
 
71
  inputs = gr.Textbox(lines=7, label="Input Text")
72
+ outputs = gr.Textbox(label="Result")
73
 
74
  # Create the Gradio interface with HTML-formatted output
75
  iface = gr.Interface(