Singularity666 commited on
Commit
377051a
·
1 Parent(s): 73eabb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -10,6 +10,7 @@ import base64
10
  from docx import Document
11
  from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
12
  from io import BytesIO
 
13
 
14
  openai.api_key = "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"
15
 
@@ -64,7 +65,8 @@ def show_predicted_caption(image, top_k=1):
64
  matches = predict_caption(
65
  image, model, text_embeddings, testing_df["caption"]
66
  )[:top_k]
67
- return matches[0].split('(')[0].strip() # Remove the reference string from the caption
 
68
 
69
  def generate_radiology_report(prompt):
70
  response = openai.Completion.create(
@@ -75,7 +77,11 @@ def generate_radiology_report(prompt):
75
  stop=None,
76
  temperature=1,
77
  )
78
- return response.choices[0].text.strip()
 
 
 
 
79
 
80
  def save_as_docx(text, filename):
81
  document = Document()
 
10
  from docx import Document
11
  from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
12
  from io import BytesIO
13
+ import re
14
 
15
  openai.api_key = "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"
16
 
 
65
  matches = predict_caption(
66
  image, model, text_embeddings, testing_df["caption"]
67
  )[:top_k]
68
+ cleaned_matches = [re.sub(r'\s\(ROCO_\d+\)', '', match) for match in matches] # Add this line to clean the matches
69
+ return cleaned_matches # Return the cleaned_matches instead of matches
70
 
71
  def generate_radiology_report(prompt):
72
  response = openai.Completion.create(
 
77
  stop=None,
78
  temperature=1,
79
  )
80
+ report = response.choices[0].text.strip()
81
+ # Remove reference string from the report
82
+ report = re.sub(r'\(ROCO_\d+\)', '', report).strip()
83
+ return report
84
+
85
 
86
  def save_as_docx(text, filename):
87
  document = Document()