Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -39,39 +39,46 @@ def conduct_debate(topic):
|
|
39 |
return response_1, response_2, conclusion
|
40 |
|
41 |
# Function to generate a properly formatted PDF
|
|
|
|
|
|
|
|
|
42 |
def generate_pdf(topic, response_1, response_2, conclusion):
|
43 |
pdf_filename = "debate_result.pdf"
|
44 |
c = canvas.Canvas(pdf_filename, pagesize=letter)
|
45 |
c.setFont("Helvetica", 12)
|
46 |
-
y_position = 750
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
c.drawString(x, y, line)
|
52 |
-
y -=
|
53 |
return y
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
y_position
|
57 |
-
|
58 |
-
c.drawString(100, y_position, "Argument in Favor:")
|
59 |
-
y_position -= 20
|
60 |
-
y_position = draw_wrapped_text(response_1, 100, y_position)
|
61 |
|
62 |
-
y_position
|
63 |
-
|
64 |
-
y_position -= 20
|
65 |
-
y_position = draw_wrapped_text(response_2, 100, y_position)
|
66 |
|
67 |
-
y_position
|
68 |
-
|
69 |
-
y_position -= 20
|
70 |
-
y_position = draw_wrapped_text(conclusion, 100, y_position)
|
71 |
|
72 |
c.save()
|
73 |
return pdf_filename
|
74 |
|
|
|
75 |
# Gradio UI
|
76 |
def debate_interface(topic):
|
77 |
response_1, response_2, conclusion = conduct_debate(topic)
|
|
|
39 |
return response_1, response_2, conclusion
|
40 |
|
41 |
# Function to generate a properly formatted PDF
|
42 |
+
from reportlab.lib.pagesizes import letter
|
43 |
+
from reportlab.pdfgen import canvas
|
44 |
+
from reportlab.lib.utils import simpleSplit
|
45 |
+
|
46 |
def generate_pdf(topic, response_1, response_2, conclusion):
|
47 |
pdf_filename = "debate_result.pdf"
|
48 |
c = canvas.Canvas(pdf_filename, pagesize=letter)
|
49 |
c.setFont("Helvetica", 12)
|
|
|
50 |
|
51 |
+
page_width, page_height = letter
|
52 |
+
x_margin, y_margin = 50, 750 # Starting position for text
|
53 |
+
line_height = 16 # Space between lines
|
54 |
+
|
55 |
+
def add_text(text, x, y):
|
56 |
+
wrapped_text = simpleSplit(text, "Helvetica", 12, page_width - 2 * x_margin)
|
57 |
+
for line in wrapped_text:
|
58 |
+
if y < 50: # If we reach the bottom margin, create a new page
|
59 |
+
c.showPage()
|
60 |
+
c.setFont("Helvetica", 12)
|
61 |
+
y = y_margin # Reset y position
|
62 |
c.drawString(x, y, line)
|
63 |
+
y -= line_height
|
64 |
return y
|
65 |
+
|
66 |
+
y_position = y_margin
|
67 |
+
y_position = add_text(f"Debate Topic: {topic}", x_margin, y_position - 20)
|
68 |
|
69 |
+
y_position = add_text("Argument in Favor:", x_margin, y_position - 30)
|
70 |
+
y_position = add_text(response_1, x_margin, y_position - 10)
|
|
|
|
|
|
|
|
|
71 |
|
72 |
+
y_position = add_text("Argument Against:", x_margin, y_position - 30)
|
73 |
+
y_position = add_text(response_2, x_margin, y_position - 10)
|
|
|
|
|
74 |
|
75 |
+
y_position = add_text("Judge's Conclusion:", x_margin, y_position - 30)
|
76 |
+
y_position = add_text(conclusion, x_margin, y_position - 10)
|
|
|
|
|
77 |
|
78 |
c.save()
|
79 |
return pdf_filename
|
80 |
|
81 |
+
|
82 |
# Gradio UI
|
83 |
def debate_interface(topic):
|
84 |
response_1, response_2, conclusion = conduct_debate(topic)
|