tosin2013 commited on
Commit
ebe866f
1 Parent(s): ad9f9f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -58
app.py CHANGED
@@ -53,64 +53,6 @@ def highlight_relevant_text(context, start, end):
53
  )
54
  return highlighted_text
55
 
56
- def find_system_font():
57
- # Adjust this function to find a suitable font
58
- font_dirs = ["/usr/share/fonts", "/usr/local/share/fonts"]
59
- for font_dir in font_dirs:
60
- ttf_files = glob.glob(os.path.join(font_dir, "**/NotoSans*.ttf"), recursive=True)
61
- if ttf_files:
62
- return ttf_files[0] # Return the first found NotoSans font
63
- raise FileNotFoundError("No suitable TTF font file found in system font directories.")
64
-
65
- def generate_pdf_report(question, answer, score, score_explanation, score_chart, highlighted_context):
66
- pdf = FPDF()
67
- pdf.add_page()
68
-
69
- # Find and use a comprehensive Unicode font like NotoSans
70
- font_path = find_system_font()
71
- pdf.add_font("NotoSans", "", font_path)
72
- pdf.set_font("NotoSans", size=12)
73
-
74
- pdf.multi_cell(0, 10, f"Question: {question}")
75
- pdf.ln()
76
-
77
- pdf.set_font("NotoSans", size=12)
78
- pdf.multi_cell(0, 10, f"Answer: {answer}")
79
- pdf.ln()
80
-
81
- pdf.set_font("NotoSans", size=12)
82
- pdf.multi_cell(0, 10, f"Confidence Score: {score}")
83
- pdf.ln()
84
-
85
- pdf.set_font("NotoSans", size=12)
86
- pdf.multi_cell(0, 10, f"Score Explanation: {score_explanation}")
87
- pdf.ln()
88
-
89
- pdf.set_font("NotoSans", size=12)
90
- pdf.multi_cell(0, 10, "Highlighted Context:")
91
- pdf.ln()
92
- pdf.set_font("NotoSans", size=10)
93
- pdf.multi_cell(0, 10, highlighted_context)
94
- pdf.ln()
95
-
96
- # Handle the image as a temporary file
97
- score_chart_image = io.BytesIO(base64.b64decode(score_chart))
98
- with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as tmpfile:
99
- tmpfile.write(score_chart_image.read())
100
- tmpfile.flush()
101
- tmpfile.close()
102
- pdf.image(tmpfile.name, x=10, y=pdf.get_y(), w=100)
103
-
104
- # Save PDF to memory
105
- pdf_output = io.BytesIO()
106
- pdf.output(pdf_output)
107
- pdf_output.seek(0)
108
-
109
- # Clean up temporary file
110
- os.remove(tmpfile.name)
111
-
112
- return pdf_output
113
-
114
  def answer_question(model_name, file, question, status):
115
  status = "Loading model..."
116
  model = load_model(model_name)
 
53
  )
54
  return highlighted_text
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  def answer_question(model_name, file, question, status):
57
  status = "Loading model..."
58
  model = load_model(model_name)