alexkueck commited on
Commit
2219824
1 Parent(s): 10eb122

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -20
app.py CHANGED
@@ -12,7 +12,9 @@ import tempfile
12
  from reportlab.pdfgen import canvas
13
  from reportlab.lib.pagesizes import letter
14
  from reportlab.pdfbase import pdfmetrics
15
- from reportlab.pdfbase.ttfonts import TTFont
 
 
16
  from PyPDF2 import PdfReader, PdfWriter
17
 
18
  from hugchat import hugchat
@@ -120,6 +122,20 @@ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffus
120
  #Textgenerierung
121
  API_URL_TEXT = "https://api-inference.huggingface.co/models/argilla/notux-8x7b-v1"
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
  ################################################
125
  #HF Hub Zugriff ermöglichen
@@ -198,30 +214,14 @@ def clear_all(history, uploaded_file_paths, chats):
198
  memoryFile = io.BytesIO()
199
  # Erstelle eine Canvas-Instanz im Bytestream
200
  c = canvas.Canvas(memoryFile, pagesize=letter) #oder A4
201
-
202
- #Inhalt des PDF formatieren:
203
- # Schriftarten
204
- TITLE_FONT = Font(Family="Times-Bold", Size=14)
205
- TEXT_FONT = Font(Family="Courier", Size=12)
206
- CODE_FONT = Font(Family="Monaco", Size=12)
207
- # Breite und Höhe für Spalten
208
- COLUMN_WIDTH = 150
209
- ROW_HEIGHT = 20
210
- # Bereiche für Spalten
211
- TIMESTAMP_X = 50
212
- USER_X = TIMESTAMP_X + COLUMN_WIDTH
213
- ASSISTANT_X = USER_X + COLUMN_WIDTH
214
- # Rand und Abstand zwischen Zeilen
215
- MARGIN = 50
216
- LINE_SPACING = 10
217
  # Zeitstempel
218
  c.setFillColorRGB(0, 0, 0)
219
- c.setFont(TITLE_FONT)
220
  c.drawCentredString(TIMESTAMP_X + COLUMN_WIDTH / 2, MARGIN, chat_history["timestamp"])
221
  # User und Assistant
222
- c.setFont(TEXT_FONT)
223
  c.drawString(USER_X, MARGIN + LINE_SPACING, chat_history["user"] + ": ")
224
- c.setFont(CODE_FONT)
225
  c.drawString(USER_X + COLUMN_WIDTH, MARGIN + LINE_SPACING, chat_history["assistant"])
226
  # Linie trennen
227
  c.line(TIMESTAMP_X, MARGIN + LINE_SPACING + ROW_HEIGHT, ASSISTANT_X + COLUMN_WIDTH, MARGIN + LINE_SPACING + ROW_HEIGHT)
 
12
  from reportlab.pdfgen import canvas
13
  from reportlab.lib.pagesizes import letter
14
  from reportlab.pdfbase import pdfmetrics
15
+ from reportlab.lib.styles import getSampleStyleSheet
16
+ from reportlab.platypus import SimpleDocTemplate, Paragraph
17
+
18
  from PyPDF2 import PdfReader, PdfWriter
19
 
20
  from hugchat import hugchat
 
122
  #Textgenerierung
123
  API_URL_TEXT = "https://api-inference.huggingface.co/models/argilla/notux-8x7b-v1"
124
 
125
+ ###############################################
126
+ # Formatierung im PDF - Konstanten setzen
127
+ # Breite und Höhe für Spalten
128
+ COLUMN_WIDTH = 150
129
+ ROW_HEIGHT = 20
130
+ # Bereiche für Spalten
131
+ TIMESTAMP_X = 50
132
+ USER_X = TIMESTAMP_X + COLUMN_WIDTH
133
+ ASSISTANT_X = USER_X + COLUMN_WIDTH
134
+ # Rand und Abstand zwischen Zeilen
135
+ MARGIN = 50
136
+ LINE_SPACING = 10
137
+
138
+
139
 
140
  ################################################
141
  #HF Hub Zugriff ermöglichen
 
214
  memoryFile = io.BytesIO()
215
  # Erstelle eine Canvas-Instanz im Bytestream
216
  c = canvas.Canvas(memoryFile, pagesize=letter) #oder A4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  # Zeitstempel
218
  c.setFillColorRGB(0, 0, 0)
219
+ c.setFont("Times-Bold", 14)
220
  c.drawCentredString(TIMESTAMP_X + COLUMN_WIDTH / 2, MARGIN, chat_history["timestamp"])
221
  # User und Assistant
222
+ c.setFont("Courier", 12)
223
  c.drawString(USER_X, MARGIN + LINE_SPACING, chat_history["user"] + ": ")
224
+ c.setFont("Monaco", 14)
225
  c.drawString(USER_X + COLUMN_WIDTH, MARGIN + LINE_SPACING, chat_history["assistant"])
226
  # Linie trennen
227
  c.line(TIMESTAMP_X, MARGIN + LINE_SPACING + ROW_HEIGHT, ASSISTANT_X + COLUMN_WIDTH, MARGIN + LINE_SPACING + ROW_HEIGHT)