Merge branch 'dev' of https://github.com/AnnaErsh/RAGnTeX into dev
Browse files- README.md +1 -1
- gfx/favicon.ico +0 -0
- gfx/icon_logo.png +3 -0
- src/compilation/latex_compilation.py +13 -5
- src/generator.py +5 -2
- src/interface/gradio_interface.py +87 -68
README.md
CHANGED
|
@@ -49,5 +49,5 @@ docker run \
|
|
| 49 |
--env-file .env \
|
| 50 |
-e IN_DOCKER=true \
|
| 51 |
-p 7860:7860 \
|
| 52 |
-
-v /
|
| 53 |
ragntex
|
|
|
|
| 49 |
--env-file .env \
|
| 50 |
-e IN_DOCKER=true \
|
| 51 |
-p 7860:7860 \
|
| 52 |
+
-v /path/to/your/output:/app/output \
|
| 53 |
ragntex
|
gfx/favicon.ico
ADDED
|
|
gfx/icon_logo.png
ADDED
|
|
Git LFS Details
|
src/compilation/latex_compilation.py
CHANGED
|
@@ -10,7 +10,7 @@ LOGGER = Logger.get_logger()
|
|
| 10 |
|
| 11 |
|
| 12 |
@observe(name="🧱 compile_presentation")
|
| 13 |
-
def compile_presentation(latex_code, work_dir) ->
|
| 14 |
"""Compile LaTeX code into a PDF presentation.
|
| 15 |
Args:
|
| 16 |
latex_code (str): LaTeX code to be compiled.
|
|
@@ -57,17 +57,25 @@ def compile_presentation(latex_code, work_dir) -> None:
|
|
| 57 |
langfuse_context.update_current_observation(
|
| 58 |
output={"pdf.success": False, "pdf.error_log": e.stderr.decode()}
|
| 59 |
)
|
| 60 |
-
LOGGER.error("❌ PDF generation failed. Here's the log: %s", e.stderr.decode())
|
| 61 |
-
else:
|
| 62 |
# Check for PDF output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
if not os.path.exists("presentation.pdf"):
|
| 64 |
langfuse_context.update_current_observation(
|
| 65 |
output={
|
| 66 |
"pdf.success": False,
|
| 67 |
-
"pdf.error_log": "❌ PDF generation
|
| 68 |
}
|
| 69 |
)
|
| 70 |
LOGGER.error("❌ PDF generation failed. No PDF file found.")
|
|
|
|
| 71 |
else:
|
| 72 |
langfuse_context.update_current_observation(output={"pdf.success": True})
|
| 73 |
-
LOGGER.info("
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
@observe(name="🧱 compile_presentation")
|
| 13 |
+
def compile_presentation(latex_code, work_dir) -> str:
|
| 14 |
"""Compile LaTeX code into a PDF presentation.
|
| 15 |
Args:
|
| 16 |
latex_code (str): LaTeX code to be compiled.
|
|
|
|
| 57 |
langfuse_context.update_current_observation(
|
| 58 |
output={"pdf.success": False, "pdf.error_log": e.stderr.decode()}
|
| 59 |
)
|
|
|
|
|
|
|
| 60 |
# Check for PDF output
|
| 61 |
+
if not os.path.exists("presentation.pdf"):
|
| 62 |
+
LOGGER.error("❌ PDF generation failed and no PDF file found. Here's the log: %s", e.stderr.decode())
|
| 63 |
+
return "❌ Presentation compilation failed. Please try again later."
|
| 64 |
+
else:
|
| 65 |
+
LOGGER.error("⚠️ PDF generation failed, but PDF file exists. Here's the log: %s", e.stderr.decode())
|
| 66 |
+
return "⚠️ Presentation compilation contains errors. Please cross-check the output."
|
| 67 |
+
else:
|
| 68 |
+
# Success, but still check for PDF output
|
| 69 |
if not os.path.exists("presentation.pdf"):
|
| 70 |
langfuse_context.update_current_observation(
|
| 71 |
output={
|
| 72 |
"pdf.success": False,
|
| 73 |
+
"pdf.error_log": "❌ PDF generation succeded, but no PDF file found.",
|
| 74 |
}
|
| 75 |
)
|
| 76 |
LOGGER.error("❌ PDF generation failed. No PDF file found.")
|
| 77 |
+
return "❌ Presentation compilation failed. Please try again later."
|
| 78 |
else:
|
| 79 |
langfuse_context.update_current_observation(output={"pdf.success": True})
|
| 80 |
+
LOGGER.info("✅ PDF generated successfully in: %s", work_dir)
|
| 81 |
+
return "⭐️ Presentation generated successfully!"
|
src/generator.py
CHANGED
|
@@ -56,8 +56,11 @@ def generate_presentation(theme, color, topic) -> tuple[str, str, str]:
|
|
| 56 |
LOGGER.info("🎲 Generated the response using: %s", model_name)
|
| 57 |
|
| 58 |
find_used_gfx(answer, work_dir, metadatas)
|
| 59 |
-
compile_presentation(answer.text, work_dir)
|
| 60 |
|
| 61 |
# delete_uploaded_files(uploaded_files)
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
LOGGER.info("🎲 Generated the response using: %s", model_name)
|
| 57 |
|
| 58 |
find_used_gfx(answer, work_dir, metadatas)
|
| 59 |
+
compilation_status = compile_presentation(answer.text, work_dir)
|
| 60 |
|
| 61 |
# delete_uploaded_files(uploaded_files)
|
| 62 |
|
| 63 |
+
if compilation_status:
|
| 64 |
+
return compilation_status, trace_id, work_dir
|
| 65 |
+
else:
|
| 66 |
+
return "❌ Unknown critial error. Please try again later.", trace_id, work_dir
|
src/interface/gradio_interface.py
CHANGED
|
@@ -44,6 +44,19 @@ def generate_iframe(folder_path) -> str:
|
|
| 44 |
return pdf_display
|
| 45 |
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
theme = gr.themes.Monochrome(
|
| 48 |
neutral_hue=gr.themes.Color(
|
| 49 |
c50="#f8f4fe",
|
|
@@ -72,26 +85,30 @@ function refresh() {
|
|
| 72 |
"""
|
| 73 |
|
| 74 |
|
| 75 |
-
def encode_image(image_path) -> str:
|
| 76 |
-
"""Encode an image file to a base64 string for embedding in HTML.
|
| 77 |
-
Args:
|
| 78 |
-
image_path (str): Path to the image file.
|
| 79 |
-
Returns:
|
| 80 |
-
str: Base64 encoded string of the image, prefixed with the appropriate data URI scheme.
|
| 81 |
-
"""
|
| 82 |
-
with open(image_path, "rb") as f:
|
| 83 |
-
data = f.read()
|
| 84 |
-
return f"data:image/png;base64,{base64.b64encode(data).decode()}"
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
IMAGE_BASE64 = encode_image("gfx/long_logo.png")
|
| 88 |
-
GITHUB_BASE64 = encode_image("gfx/github-mark-white.png")
|
| 89 |
-
|
| 90 |
-
|
| 91 |
with gr.Blocks(theme=theme, js=JS_FUNC) as demo:
|
| 92 |
uploaded_files_state = gr.State([])
|
| 93 |
presentation_folder_state = gr.State("")
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
# Mess with the download-box
|
| 96 |
gr.HTML(
|
| 97 |
"""
|
|
@@ -115,7 +132,7 @@ with gr.Blocks(theme=theme, js=JS_FUNC) as demo:
|
|
| 115 |
<div style="text-align:center;">
|
| 116 |
<img src="{IMAGE_BASE64}" style="max-width: 100%; height: auto;" />
|
| 117 |
</div>
|
| 118 |
-
|
| 119 |
)
|
| 120 |
with gr.Column(scale=1):
|
| 121 |
gr.Markdown(
|
|
@@ -129,6 +146,32 @@ with gr.Blocks(theme=theme, js=JS_FUNC) as demo:
|
|
| 129 |
'<div style="text-align:justify; margin-top: 0px;">Just upload your PDFs, click <b>Upload Files</b>, '
|
| 130 |
"choose a theme, enter your topic, and hit <b>Generate Presentation</b> — it's that easy!</div>"
|
| 131 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
with gr.Row():
|
| 134 |
with gr.Column(scale=1):
|
|
@@ -239,9 +282,9 @@ with gr.Blocks(theme=theme, js=JS_FUNC) as demo:
|
|
| 239 |
|
| 240 |
gr.Markdown("<br>")
|
| 241 |
|
| 242 |
-
gr.Markdown("## ⭐ Rate Us")
|
| 243 |
with gr.Row():
|
| 244 |
with gr.Column(scale=1):
|
|
|
|
| 245 |
rating = gr.Radio(
|
| 246 |
choices=["⭐️", "⭐️⭐️", "⭐️⭐️⭐️", "⭐️⭐️⭐️⭐️", "⭐️⭐️⭐️⭐️⭐️"],
|
| 247 |
label="How would you rate this app?",
|
|
@@ -258,65 +301,41 @@ with gr.Blocks(theme=theme, js=JS_FUNC) as demo:
|
|
| 258 |
max_lines=5,
|
| 259 |
interactive=True,
|
| 260 |
)
|
| 261 |
-
with gr.Column(scale=1):
|
| 262 |
submit_feedback_button = gr.Button("Submit Feedback", variant="secondary")
|
| 263 |
feedback_output = gr.Textbox(
|
| 264 |
-
label="Feedback Status", interactive=False, lines=
|
| 265 |
)
|
| 266 |
|
| 267 |
-
gr.Markdown("## 🙌 Credits")
|
| 268 |
-
with gr.Row():
|
| 269 |
-
with gr.Column(scale=1):
|
| 270 |
-
gr.Markdown(
|
| 271 |
-
'<div style="text-align:justify; margin-top: 0px;">'
|
| 272 |
-
"RAG'n'TeX is a collaborative effort by a team of developers and researchers driven "
|
| 273 |
-
"to make the everyday work of scientists and professionals easier. By combining LaTeX with AI, "
|
| 274 |
-
"we create smart tools that help you build polished, accurate presentations quickly and smoothly. "
|
| 275 |
-
"Our goal is to make the process simple and stress-free, so you can spend more time on what really matters.</div>\n\n"
|
| 276 |
-
)
|
| 277 |
with gr.Column(scale=1):
|
|
|
|
| 278 |
gr.HTML(
|
| 279 |
f"""
|
| 280 |
-
<div style="display: flex; flex-direction:
|
| 281 |
-
|
| 282 |
-
<
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
cursor: pointer;
|
| 299 |
-
gap: 8px;
|
| 300 |
-
transition: background-color 0.2s ease-in-out;
|
| 301 |
-
"
|
| 302 |
-
onmouseover="this.style.backgroundColor='#6d28d9';"
|
| 303 |
-
onmouseout="this.style.backgroundColor='#4c1d95';"
|
| 304 |
-
>
|
| 305 |
-
<img src="{GITHUB_BASE64}" alt="GitHub" style="height: 20px; margin: 0;">
|
| 306 |
-
RAG'n'TeX
|
| 307 |
-
</a>
|
| 308 |
</div>
|
| 309 |
-
"""
|
| 310 |
-
)
|
| 311 |
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
gr.Markdown(
|
| 319 |
-
"📄 Licensed under the [MIT License](https://opensource.org/licenses/MIT)"
|
| 320 |
)
|
| 321 |
|
| 322 |
upload_button.click(
|
|
|
|
| 44 |
return pdf_display
|
| 45 |
|
| 46 |
|
| 47 |
+
def encode_image(image_path):
|
| 48 |
+
with open(image_path, "rb") as f:
|
| 49 |
+
data = f.read()
|
| 50 |
+
return f"data:image/png;base64,{base64.b64encode(data).decode()}"
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
banner_base64 = encode_image("gfx/long_logo.png")
|
| 54 |
+
logo_base64 = encode_image("gfx/icon_logo.png")
|
| 55 |
+
github_base64 = encode_image("gfx/github-mark-white.png")
|
| 56 |
+
favicon_base64 = encode_image("gfx/favicon.ico")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# Custom Gradio theme
|
| 60 |
theme = gr.themes.Monochrome(
|
| 61 |
neutral_hue=gr.themes.Color(
|
| 62 |
c50="#f8f4fe",
|
|
|
|
| 85 |
"""
|
| 86 |
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
with gr.Blocks(theme=theme, js=JS_FUNC) as demo:
|
| 89 |
uploaded_files_state = gr.State([])
|
| 90 |
presentation_folder_state = gr.State("")
|
| 91 |
|
| 92 |
+
# Page title and favicon (doesn't work? Gradio is really agressive)
|
| 93 |
+
gr.HTML(
|
| 94 |
+
f"""
|
| 95 |
+
<script>
|
| 96 |
+
document.title = "RAG'n'TeX Presentation Generator";
|
| 97 |
+
|
| 98 |
+
const links = document.querySelectorAll("link[rel*='icon']");
|
| 99 |
+
links.forEach(link => link.parentNode.removeChild(link));
|
| 100 |
+
|
| 101 |
+
const newFavicon = document.createElement('link');
|
| 102 |
+
newFavicon.rel = 'icon';
|
| 103 |
+
newFavicon.type = 'image/png';
|
| 104 |
+
newFavicon.href = '{favicon_base64}';
|
| 105 |
+
document.head.appendChild(newFavicon);
|
| 106 |
+
</script>
|
| 107 |
+
""",
|
| 108 |
+
elem_id="custom-head-injection",
|
| 109 |
+
visible=False,
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
# Mess with the download-box
|
| 113 |
gr.HTML(
|
| 114 |
"""
|
|
|
|
| 132 |
<div style="text-align:center;">
|
| 133 |
<img src="{IMAGE_BASE64}" style="max-width: 100%; height: auto;" />
|
| 134 |
</div>
|
| 135 |
+
"""
|
| 136 |
)
|
| 137 |
with gr.Column(scale=1):
|
| 138 |
gr.Markdown(
|
|
|
|
| 146 |
'<div style="text-align:justify; margin-top: 0px;">Just upload your PDFs, click <b>Upload Files</b>, '
|
| 147 |
"choose a theme, enter your topic, and hit <b>Generate Presentation</b> — it's that easy!</div>"
|
| 148 |
)
|
| 149 |
+
gr.HTML(
|
| 150 |
+
f"""
|
| 151 |
+
<div style="display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 12px; margin-bottom: 12px;">
|
| 152 |
+
<p style="font-size: 16px;">Please ⭐️ us on GitHub!</p>
|
| 153 |
+
<a href="https://github.com/RAGnTeX/RAGnTeX" target="_blank" style="
|
| 154 |
+
display: inline-flex;
|
| 155 |
+
align-items: center;
|
| 156 |
+
justify-content: center;
|
| 157 |
+
padding: 12px 16px;
|
| 158 |
+
background-color: #4c1d95;
|
| 159 |
+
color: white;
|
| 160 |
+
font-weight: 600;
|
| 161 |
+
border-radius: 8px;
|
| 162 |
+
text-decoration: none;
|
| 163 |
+
gap: 8px;
|
| 164 |
+
transition: background-color 0.2s ease-in-out;
|
| 165 |
+
"
|
| 166 |
+
onmouseover="this.style.backgroundColor='#6d28d9';"
|
| 167 |
+
onmouseout="this.style.backgroundColor='#4c1d95';"
|
| 168 |
+
>
|
| 169 |
+
<img src="{github_base64}" alt="GitHub" style="height: 20px;">
|
| 170 |
+
RAG'n'TeX
|
| 171 |
+
</a>
|
| 172 |
+
</div>
|
| 173 |
+
"""
|
| 174 |
+
)
|
| 175 |
|
| 176 |
with gr.Row():
|
| 177 |
with gr.Column(scale=1):
|
|
|
|
| 282 |
|
| 283 |
gr.Markdown("<br>")
|
| 284 |
|
|
|
|
| 285 |
with gr.Row():
|
| 286 |
with gr.Column(scale=1):
|
| 287 |
+
gr.Markdown("## ⭐ Rate Us")
|
| 288 |
rating = gr.Radio(
|
| 289 |
choices=["⭐️", "⭐️⭐️", "⭐️⭐️⭐️", "⭐️⭐️⭐️⭐️", "⭐️⭐️⭐️⭐️⭐️"],
|
| 290 |
label="How would you rate this app?",
|
|
|
|
| 301 |
max_lines=5,
|
| 302 |
interactive=True,
|
| 303 |
)
|
|
|
|
| 304 |
submit_feedback_button = gr.Button("Submit Feedback", variant="secondary")
|
| 305 |
feedback_output = gr.Textbox(
|
| 306 |
+
label="Feedback Status", interactive=False, lines=2
|
| 307 |
)
|
| 308 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
with gr.Column(scale=1):
|
| 310 |
+
gr.Markdown("## 🙌 Credits")
|
| 311 |
gr.HTML(
|
| 312 |
f"""
|
| 313 |
+
<div style="display: flex; flex-direction: row; gap: 24px; margin-top: 0; align-items: flex-start;">
|
| 314 |
+
|
| 315 |
+
<!-- Left Column -->
|
| 316 |
+
<div style="flex: 1;">
|
| 317 |
+
<div style="text-align:justify; margin-top: 0px;">
|
| 318 |
+
<p> RAG'n'TeX is a collaborative effort by a team of developers and researchers driven
|
| 319 |
+
to make the everyday work of scientists and professionals easier. By combining LaTeX with AI,
|
| 320 |
+
we create smart tools that help you build polished, accurate presentations quickly and smoothly.
|
| 321 |
+
Our goal is to make the process simple and stress-free, so you can spend more time on what really matters.</p>
|
| 322 |
+
<br>
|
| 323 |
+
<p>📄 Licensed under the <a href="https://opensource.org/licenses/MIT" target="_blank" rel="noopener noreferrer">MIT License</a></p>
|
| 324 |
+
<br>
|
| 325 |
+
<h4>Authors:</h4>
|
| 326 |
+
<ul style="padding-left: 20px; margin-top: 4px;">
|
| 327 |
+
<li>👩🏻💻 <a href="https://github.com/AnnaErsh" target="_blank">Anna Ershova</a></li>
|
| 328 |
+
<li>👨🏼🔬 <a href="https://github.com/KajetanNiewczas" target="_blank">Kajetan Niewczas</a></li>
|
| 329 |
+
</ul>
|
| 330 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
</div>
|
|
|
|
|
|
|
| 332 |
|
| 333 |
+
<!-- Right Column -->
|
| 334 |
+
<div style="flex: 1; display: flex; justify-content: flex-end; align-items: center;">
|
| 335 |
+
<img src="{logo_base64}" alt="Illustration" style="max-width: 100%; border-radius: 8px;">
|
| 336 |
+
</div>
|
| 337 |
+
</div>
|
| 338 |
+
"""
|
|
|
|
|
|
|
| 339 |
)
|
| 340 |
|
| 341 |
upload_button.click(
|