smolinski commited on
Commit
c3c46f1
·
verified ·
1 Parent(s): b02c42c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -7
app.py CHANGED
@@ -229,11 +229,7 @@ def response(query, historia=None):
229
  # the response to the Gradio App
230
  response = llm(rag_prompt)
231
 
232
- # return response.content if response and response.content else "Brak odpowiedzi.", sources_markdown, zrodla, cytaty # ✅ Teraz zwracamy także źródła dla pliku Word
233
-
234
  return response.content if response and response.content else "Brak odpowiedzi.", sources_markdown, cytaty
235
-
236
- #return str(response.content).strip() if response and response.content else "Brak odpowiedzi.", sources_markdown, cytaty
237
 
238
 
239
 
@@ -303,6 +299,40 @@ def zapisz_odpowiedz(odpowiedz, pytanie, sources, user_path):
303
  paragraph.paragraph_format.space_before = Pt(0)
304
  paragraph.paragraph_format.space_after = Pt(5)
305
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
  p1 = doc.add_paragraph()
307
  formatuj_naglowek(p1, "Pytanie:")
308
  p1 = doc.add_paragraph(pytanie)
@@ -312,9 +342,8 @@ def zapisz_odpowiedz(odpowiedz, pytanie, sources, user_path):
312
 
313
  p2 = doc.add_paragraph()
314
  formatuj_naglowek(p2, "Odpowiedź:")
315
- p2 = doc.add_paragraph(odpowiedz)
316
- formatuj_paragraf(p2)
317
-
318
  doc.add_paragraph(" ")
319
 
320
  if sources and sources.strip():
 
229
  # the response to the Gradio App
230
  response = llm(rag_prompt)
231
 
 
 
232
  return response.content if response and response.content else "Brak odpowiedzi.", sources_markdown, cytaty
 
 
233
 
234
 
235
 
 
299
  paragraph.paragraph_format.space_before = Pt(0)
300
  paragraph.paragraph_format.space_after = Pt(5)
301
 
302
+ def dodaj_markdown_tekst(doc, text):
303
+ lines = text.splitlines()
304
+ for line in lines:
305
+ # Lista wypunktowana
306
+ if line.strip().startswith(("- ", "* ")):
307
+ para = doc.add_paragraph(style='List Bullet')
308
+ content = line.strip()[2:]
309
+ # Cytat
310
+ elif line.strip().startswith("> "):
311
+ para = doc.add_paragraph()
312
+ para.paragraph_format.left_indent = Pt(20)
313
+ content = line.strip()[2:]
314
+ else:
315
+ para = doc.add_paragraph()
316
+ content = line
317
+
318
+ # Markdown inline: **bold**, *italic*, ~~strikethrough~~
319
+ pattern = r"(\*\*.*?\*\*|\*.*?\*|~~.*?~~|[^*~]+)"
320
+ parts = re.findall(pattern, content)
321
+
322
+ for part in parts:
323
+ clean = part.replace("**", "").replace("*", "").replace("~~", "")
324
+ run = para.add_run(clean)
325
+
326
+ if part.startswith("**") and part.endswith("**"):
327
+ run.bold = True
328
+ elif part.startswith("*") and part.endswith("*"):
329
+ run.italic = True
330
+ elif part.startswith("~~") and part.endswith("~~"):
331
+ run.font.strike = True
332
+
333
+ run.font.name = "Calibri"
334
+ run.font.size = Pt(12)
335
+
336
  p1 = doc.add_paragraph()
337
  formatuj_naglowek(p1, "Pytanie:")
338
  p1 = doc.add_paragraph(pytanie)
 
342
 
343
  p2 = doc.add_paragraph()
344
  formatuj_naglowek(p2, "Odpowiedź:")
345
+ dodaj_markdown_tekst(doc, odpowiedz)
346
+
 
347
  doc.add_paragraph(" ")
348
 
349
  if sources and sources.strip():