Spaces:
Runtime error
Runtime error
File size: 3,526 Bytes
a1e6c4a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
import os
import sys
from generate_markdown import load_llm_model, generate_markdown, sanitize_markdown
from generate_mindmap import generate_mindmap
import gradio as gr
import subprocess
def generate(file):
print(f"Generating mindmap for {file.name}")
unformatted_markdown = True
summary = "This is a summary of the research paper"
mindmap_markdown = generate_markdown(llm, file)
print('mindmap_markdown:', mindmap_markdown)
while unformatted_markdown:
if mindmap_markdown.startswith("#") and '-' in mindmap_markdown:
unformatted_markdown = False
mindmap_svg, mindmap_pdf = generate_mindmap(mindmap_markdown)
else:
unformatted_markdown = True
mindmap_markdown = sanitize_markdown(llm, mindmap_markdown)
print("Mindmap generated successfully")
return summary, mindmap_markdown, mindmap_svg, mindmap_svg, mindmap_pdf, mindmap_pdf
theme = gr.themes.Soft(
primary_hue="purple",
secondary_hue="cyan",
neutral_hue="slate",
font=[gr.themes.GoogleFont('Syne'), gr.themes.GoogleFont('Poppins')],
)
with gr.Blocks(theme=theme, title="Binary Biology") as app:
with gr.Row():
file = gr.File(file_count='single', label='Upload Research Paper PDF file', file_types=['.pdf'])
with gr.Column():
submit = gr.Button(value='Submit')
clear = gr.ClearButton(value='Clear')
with gr.Row():
summary = gr.TextArea(label='Summary', lines=5, interactive=False, show_copy_button=True)
markdown_mindmap = gr.Textbox(label='Mindmap', lines=5, interactive=False, show_copy_button=True)
with gr.Row():
with gr.Column():
svg_mindmap = gr.File(label='Graphical SVG Mindmap', interactive=False)
download_svg_mindmap = gr.File(label='Download SVG Mindmap', interactive=False)
with gr.Column():
pdf_mindmap = gr.File(label='Graphical PDF Mindmap', interactive=False)
download_pdf_mindmap = gr.File(label='Download PDF Mindmap', interactive=False)
submit.click(
generate,
inputs=[file],
outputs=[summary, markdown_mindmap, svg_mindmap, download_svg_mindmap, pdf_mindmap, download_pdf_mindmap],
scroll_to_output=True,
show_progress='minimal',
queue=True,
)
clear.click(
lambda: (None, None, None, None, None, None),
inputs=[file],
outputs=[summary, markdown_mindmap, svg_mindmap, download_svg_mindmap, pdf_mindmap, download_pdf_mindmap]
)
if __name__ == "__main__":
try:
env = os.environ.copy()
env["CMAKE_ARGS"] = "-DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS"
subprocess.run(["pip", "install", "llama-cpp-python"], env=env)
except Exception as e:
print(f"Failed to install llama-cpp-python: {e}")
try:
subprocess.run(['apt', 'install', '-y', 'graphviz'])
print("Graphviz installed successfully")
except Exception:
try:
subprocess.run(['sudo', 'apt', 'install', '-y', 'graphviz'])
print("Graphviz installed successfully using sudo")
except:
print("Graphviz installation failed")
sys.exit(1)
print("Graphviz loaded successfully")
llm = load_llm_model()
print("Model loaded successfully")
app.queue(default_concurrency_limit=1).launch(show_error=True)
|