eranmi commited on
Commit
0c3065c
·
2 Parent(s): fa9db6600c9790

Merge branch 'dev' of https://github.com/AnnaErsh/RAGnTeX into dev

Browse files
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 RAGnTeX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
gfx/github-mark-white.png ADDED

Git LFS Details

  • SHA256: 60d03f0f1a09aafcc2df2e10b4ffd24eab44787b451f8fdb367c3baf589cf95a
  • Pointer size: 129 Bytes
  • Size of remote file: 4.84 kB
src/interface/download_files.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import zipfile
2
+ from pathlib import Path
3
+ from ..telemetry.logging_utils import Logger
4
+
5
+ LOGGER = Logger.get_logger()
6
+
7
+
8
+ def download_files(folder_path) -> str:
9
+ """Prepare downloadable zip archive from the specified folder path."""
10
+
11
+ if not folder_path:
12
+ return "No folder path provided."
13
+
14
+ folder = Path(folder_path)
15
+ zip_path = Path.cwd() / "presentation.zip"
16
+
17
+ with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
18
+ for file in folder.rglob('*'):
19
+ if file.is_file() and file != zip_path:
20
+ arcname = Path("presentation") / file.relative_to(folder)
21
+ zipf.write(file, arcname=arcname)
22
+ LOGGER.info("📦 Created zip archive at %s", zip_path)
23
+
24
+ return str(zip_path)
src/interface/gradio_interface.py CHANGED
@@ -2,6 +2,7 @@
2
 
3
  import gradio as gr
4
  from .upload_files import upload_files
 
5
  from ..services import generate_presentation
6
  from ..telemetry import submit_feedback
7
  import base64
@@ -21,19 +22,20 @@ def upload_and_update_list(files: list, uploaded_list) -> tuple[str, list[str]]:
21
  return status, updated_list
22
 
23
 
24
- def generate_iframe(file_path):
 
25
  if not file_path:
26
  return ""
27
  else:
28
  with open(file_path, "rb") as f:
29
  base64_pdf = base64.b64encode(f.read()).decode("utf-8")
30
- # pdf_display = f'''
31
- # <div style="position:relative; width:100%; padding-top:76.5%;">
32
- # <iframe src="data:application/pdf;base64,{base64_pdf}#view=FitH"
33
- # style="position:absolute; top:0; left:0; width:100%; height:100%; border:none;">
34
- # </iframe></div>
35
- # '''
36
- pdf_display = f'<iframe width="100%" height="auto" src="data:application/pdf;base64,{base64_pdf}"></iframe>'
37
  return pdf_display
38
 
39
 
@@ -72,10 +74,25 @@ def encode_image(image_path):
72
 
73
 
74
  image_base64 = encode_image("gfx/long_logo.png")
 
75
 
76
 
77
  with gr.Blocks(theme=theme, js=js_func) as demo:
78
  uploaded_files_state = gr.State([])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  gr.Markdown(
81
  '<h1 style="text-align:center;">AI-powered LaTeX Presentation Generator</h1>'
@@ -189,7 +206,31 @@ with gr.Blocks(theme=theme, js=js_func) as demo:
189
  )
190
  submit_topic_button = gr.Button("Generate Presentation", variant="primary")
191
 
192
- gr.Markdown("## ⭐ Rate Us")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  rating = gr.Radio(
194
  choices=["⭐️", "⭐️⭐️", "⭐️⭐️⭐️", "⭐️⭐️⭐️⭐️", "⭐️⭐️⭐️⭐️⭐️"],
195
  label="How would you rate this app?",
@@ -206,23 +247,66 @@ with gr.Blocks(theme=theme, js=js_func) as demo:
206
  max_lines=5,
207
  interactive=True,
208
  )
 
209
  submit_feedback_button = gr.Button("Submit Feedback", variant="secondary")
210
- feedback_output = gr.Textbox(label="Feedback Status", interactive=False)
 
 
211
 
 
 
212
  with gr.Column(scale=1):
213
- gr.Markdown("## 📄 Uploaded Files")
214
- upload_output = gr.Textbox(
215
- label="Upload Status", lines=3, interactive=False
 
 
 
216
  )
217
-
218
- gr.Markdown("## 📝 Presentation Processing")
219
- topic_output = gr.Textbox(
220
- label="Compilation Status", lines=1, interactive=False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  )
222
 
223
- gr.Markdown("## 🎉 Final Presentation")
224
- pdf_output = gr.File(label="Download/View Presentation")
225
- pdf_output_viewer = gr.HTML(label="Presentation Preview")
 
 
 
 
 
 
226
 
227
  upload_button.click(
228
  fn=upload_and_update_list,
@@ -239,12 +323,18 @@ with gr.Blocks(theme=theme, js=js_func) as demo:
239
  topic_input,
240
  uploaded_files_state,
241
  ],
242
- outputs=[topic_output, pdf_output, pdf_output_viewer, trace_id_state],
 
 
 
 
 
 
243
  )
244
 
245
  pdf_output.change(
246
  fn=generate_iframe,
247
- inputs=pdf_output,
248
  outputs=pdf_output_viewer,
249
  )
250
 
 
2
 
3
  import gradio as gr
4
  from .upload_files import upload_files
5
+ from .download_files import download_files
6
  from ..services import generate_presentation
7
  from ..telemetry import submit_feedback
8
  import base64
 
22
  return status, updated_list
23
 
24
 
25
+ def generate_iframe(folder_path):
26
+ file_path = f"{folder_path}/presentation.pdf"
27
  if not file_path:
28
  return ""
29
  else:
30
  with open(file_path, "rb") as f:
31
  base64_pdf = base64.b64encode(f.read()).decode("utf-8")
32
+ pdf_display = f"""
33
+ <div style="position:relative; width:100%; padding-top:76.5%;">
34
+ <iframe src="data:application/pdf;base64,{base64_pdf}#view=FitH"
35
+ style="position:absolute; top:0; left:0; width:100%; height:100%; border:none;">
36
+ </iframe></div>
37
+ """
38
+ # pdf_display = f'<iframe width="100%" height="600" src="data:application/pdf;base64,{base64_pdf}"></iframe>'
39
  return pdf_display
40
 
41
 
 
74
 
75
 
76
  image_base64 = encode_image("gfx/long_logo.png")
77
+ github_base64 = encode_image("gfx/github-mark-white.png")
78
 
79
 
80
  with gr.Blocks(theme=theme, js=js_func) as demo:
81
  uploaded_files_state = gr.State([])
82
+ presentation_folder_state = gr.State("")
83
+
84
+ # Mess with the download-box
85
+ gr.HTML(
86
+ """
87
+ <style>
88
+ #download-box svg.feather-file {
89
+ display: none !important;
90
+ }
91
+ </style>
92
+ """,
93
+ elem_id="custom-style-injection",
94
+ visible=False,
95
+ )
96
 
97
  gr.Markdown(
98
  '<h1 style="text-align:center;">AI-powered LaTeX Presentation Generator</h1>'
 
206
  )
207
  submit_topic_button = gr.Button("Generate Presentation", variant="primary")
208
 
209
+ with gr.Column(scale=1):
210
+ gr.Markdown("## 📄 Uploaded Files")
211
+ upload_output = gr.Textbox(
212
+ label="Upload Status", lines=3, interactive=False
213
+ )
214
+
215
+ gr.Markdown("## 📝 Presentation Processing")
216
+ compilation_status = gr.Textbox(
217
+ label="Compilation Status", lines=1, interactive=False
218
+ )
219
+
220
+ gr.Markdown("## 🎉 Final Presentation")
221
+ pdf_output = gr.File(
222
+ label="Download/View Presentation",
223
+ interactive=False,
224
+ elem_id="download-box",
225
+ )
226
+ pdf_output_viewer = gr.HTML(label="Presentation Preview")
227
+ trace_id_state = gr.State("")
228
+
229
+ gr.Markdown("<br>")
230
+
231
+ gr.Markdown("## ⭐ Rate Us")
232
+ with gr.Row():
233
+ with gr.Column(scale=1):
234
  rating = gr.Radio(
235
  choices=["⭐️", "⭐️⭐️", "⭐️⭐️⭐️", "⭐️⭐️⭐️⭐️", "⭐️⭐️⭐️⭐️⭐️"],
236
  label="How would you rate this app?",
 
247
  max_lines=5,
248
  interactive=True,
249
  )
250
+ with gr.Column(scale=1):
251
  submit_feedback_button = gr.Button("Submit Feedback", variant="secondary")
252
+ feedback_output = gr.Textbox(
253
+ label="Feedback Status", interactive=False, lines=4
254
+ )
255
 
256
+ gr.Markdown("## 🙌 Credits")
257
+ with gr.Row():
258
  with gr.Column(scale=1):
259
+ gr.Markdown(
260
+ '<div style="text-align:justify; margin-top: 0px;">'
261
+ "RAG'n'TeX is a collaborative effort by a team of developers and researchers driven "
262
+ "to make the everyday work of scientists and professionals easier. By combining LaTeX with AI, "
263
+ "we create smart tools that help you build polished, accurate presentations quickly and smoothly. "
264
+ "Our goal is to make the process simple and stress-free, so you can spend more time on what really matters.</div>\n\n"
265
  )
266
+ with gr.Column(scale=1):
267
+ gr.HTML(
268
+ f"""
269
+ <div style="display: flex; flex-direction: column; align-items: stretch;
270
+ gap: 8px; margin: 0; font-family: inherit;">
271
+ <p style="margin: 0 0 8px 0; padding: 0; font-size: 16px; font-family: inherit; text-align: center;">
272
+ Please ⭐️ us on GitHub!
273
+ </p>
274
+ <a href="https://github.com/RAGnTeX/RAGnTeX" target="_blank" style="
275
+ display: inline-flex;
276
+ align-items: center;
277
+ justify-content: center;
278
+ width: 100%;
279
+ padding: 12px;
280
+ background-color: #4c1d95;
281
+ color: white;
282
+ font-weight: 600;
283
+ font-family: inherit;
284
+ border-radius: 0;
285
+ text-decoration: none;
286
+ user-select: none;
287
+ cursor: pointer;
288
+ gap: 8px;
289
+ transition: background-color 0.2s ease-in-out;
290
+ "
291
+ onmouseover="this.style.backgroundColor='#6d28d9';"
292
+ onmouseout="this.style.backgroundColor='#4c1d95';"
293
+ >
294
+ <img src="{github_base64}" alt="GitHub" style="height: 20px; margin: 0;">
295
+ RAG'n'TeX
296
+ </a>
297
+ </div>
298
+ """
299
  )
300
 
301
+ with gr.Column(scale=1):
302
+ gr.Markdown(
303
+ "#### Authors:\n"
304
+ "- 👩🏻‍💻 **[Anna Ershova](https://github.com/AnnaErsh)**\n"
305
+ "- 👨🏼‍🔬 **[Kajetan Niewczas](https://github.com/KajetanNiewczas)**\n"
306
+ )
307
+ gr.Markdown(
308
+ "📄 Licensed under the [MIT License](https://opensource.org/licenses/MIT)"
309
+ )
310
 
311
  upload_button.click(
312
  fn=upload_and_update_list,
 
323
  topic_input,
324
  uploaded_files_state,
325
  ],
326
+ outputs=[compilation_status, trace_id_state, presentation_folder_state],
327
+ )
328
+
329
+ compilation_status.change(
330
+ fn=download_files,
331
+ inputs=presentation_folder_state,
332
+ outputs=pdf_output,
333
  )
334
 
335
  pdf_output.change(
336
  fn=generate_iframe,
337
+ inputs=presentation_folder_state,
338
  outputs=pdf_output_viewer,
339
  )
340
 
src/services/generator.py CHANGED
@@ -27,8 +27,8 @@ def generate_presentation(theme, color, topic, uploaded_files) -> tuple[str, str
27
  Returns:
28
  tuple: A 3-element tuple:
29
  - str: Success message.
30
- - str: Path to the generated presentation.
31
- - str: Placeholder for the output viewer.
32
  """
33
 
34
  trace_id = langfuse_context.get_current_trace_id()
@@ -61,6 +61,6 @@ def generate_presentation(theme, color, topic, uploaded_files) -> tuple[str, str
61
  find_used_gfx(answer, work_dir, metadatas)
62
  compile_presentation(answer.text, work_dir)
63
 
64
- delete_uploaded_files(uploaded_files)
65
- output_path = Path(work_dir + "/presentation.pdf")
66
- return "Presentation generated successfully!", str(output_path), "", trace_id
 
27
  Returns:
28
  tuple: A 3-element tuple:
29
  - str: Success message.
30
+ - str: Trace ID for telemetry purposes.
31
+ - str: Path to the presentation folder.
32
  """
33
 
34
  trace_id = langfuse_context.get_current_trace_id()
 
61
  find_used_gfx(answer, work_dir, metadatas)
62
  compile_presentation(answer.text, work_dir)
63
 
64
+ delete_uploaded_files(uploaded_files)
65
+
66
+ return "Presentation generated successfully!", trace_id, work_dir