Spaces:
Sleeping
Sleeping
init app
Browse files- .gitattributes +1 -0
- app.py +125 -0
- requirements.txt +1 -0
- tests/examples/ashortsurvey.pdf +3 -0
- tests/examples/attentionisallyouneed.pdf +3 -0
- tests/examples/bert.pdf +3 -0
.gitattributes
CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*.pdf filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
from paper2cmap import Paper2CMap
|
5 |
+
|
6 |
+
|
7 |
+
def set_key(openai_api_key):
|
8 |
+
os.environ["OPENAI_API_TYPE"] = "openai"
|
9 |
+
os.environ["OPENAI_API_KEY"] = openai_api_key
|
10 |
+
os.environ["OPENAI_MODEL_NAME"] = "gpt-3.5-turbo"
|
11 |
+
return openai_api_key
|
12 |
+
|
13 |
+
|
14 |
+
def load_text(state, paper_path, temperature, max_num_sections):
|
15 |
+
paper2cmap = Paper2CMap(temperature=temperature)
|
16 |
+
paper2cmap.load(paper_path.name)
|
17 |
+
if max_num_sections == -1:
|
18 |
+
text = paper2cmap.paper_reader.full_text
|
19 |
+
else:
|
20 |
+
text = "\n\n".join(paper2cmap.paper_reader.sections[:max_num_sections])
|
21 |
+
|
22 |
+
state["paper2cmap"] = paper2cmap
|
23 |
+
return state, text
|
24 |
+
|
25 |
+
|
26 |
+
def generate_cmap(state, max_num_concepts, max_num_links, max_num_sections):
|
27 |
+
paper2cmap = state["paper2cmap"]
|
28 |
+
cmap = paper2cmap.generate_cmap(
|
29 |
+
max_num_concepts=max_num_concepts,
|
30 |
+
max_num_relationships=max_num_links,
|
31 |
+
max_num_iterations=max_num_sections,
|
32 |
+
)
|
33 |
+
|
34 |
+
del state["paper2cmap"]
|
35 |
+
return state, cmap
|
36 |
+
|
37 |
+
|
38 |
+
css = ".json {height: 657px; overflow: scroll;} .json-holder {height: 657px; overflow: scroll;}"
|
39 |
+
with gr.Blocks(css=css) as demo:
|
40 |
+
state = gr.State(value={})
|
41 |
+
gr.Markdown("<h1><center><a href='https://github.com/whiskyboy/paper2cmap'>Paper2CMap</a></center></h1>")
|
42 |
+
gr.Markdown("<p align='center' style='font-size: 20px;'>A library to generate concept map from a research paper. Powered by LLM.</p>")
|
43 |
+
|
44 |
+
# Set Key
|
45 |
+
with gr.Row():
|
46 |
+
with gr.Column(scale=0.85):
|
47 |
+
openai_api_key = gr.Textbox(
|
48 |
+
show_label=False,
|
49 |
+
placeholder="Set your OpenAI API key here and press Enter",
|
50 |
+
lines=1,
|
51 |
+
type="password"
|
52 |
+
).style(container=False)
|
53 |
+
with gr.Column(scale=0.15, min_width=0):
|
54 |
+
set_key_btn = gr.Button("Submit")
|
55 |
+
|
56 |
+
# Inputs
|
57 |
+
with gr.Row():
|
58 |
+
with gr.Column(scale=0.25):
|
59 |
+
# Set Parameters
|
60 |
+
temperature = gr.Slider(
|
61 |
+
minimum=0.0,
|
62 |
+
maximum=2.0,
|
63 |
+
value=0.2,
|
64 |
+
step=0.1,
|
65 |
+
label="Temperature",
|
66 |
+
interactive=True,
|
67 |
+
)
|
68 |
+
max_num_concepts = gr.Number(
|
69 |
+
value=10,
|
70 |
+
label="Max Number of Concepts",
|
71 |
+
interactive=True,
|
72 |
+
precision=0,
|
73 |
+
)
|
74 |
+
max_num_links = gr.Number(
|
75 |
+
value=30,
|
76 |
+
label="Max Number of Links",
|
77 |
+
interactive=True,
|
78 |
+
precision=0,
|
79 |
+
)
|
80 |
+
max_num_sections = gr.Number(
|
81 |
+
value=-1,
|
82 |
+
label="Max Number of Sections",
|
83 |
+
interactive=True,
|
84 |
+
precision=0,
|
85 |
+
)
|
86 |
+
|
87 |
+
# Upload File
|
88 |
+
paper_path = gr.File(file_types=[".pdf"], label="PDF")
|
89 |
+
|
90 |
+
# Generate Button
|
91 |
+
generate_btn = gr.Button("Generate")
|
92 |
+
|
93 |
+
# Outputs
|
94 |
+
with gr.Column(scale=0.75):
|
95 |
+
# Output Text
|
96 |
+
text = gr.Textbox(lines=10, max_lines=10, label="Text", interactive=False)
|
97 |
+
# Output Concept Map
|
98 |
+
concept_map = gr.JSON(label="Concept Map")
|
99 |
+
|
100 |
+
# Event Handlers
|
101 |
+
openai_api_key.submit(set_key, [openai_api_key], [openai_api_key])
|
102 |
+
set_key_btn.click(set_key, [openai_api_key], [openai_api_key])
|
103 |
+
|
104 |
+
generate_btn.click(
|
105 |
+
fn=load_text,
|
106 |
+
inputs=[state, paper_path, temperature, max_num_sections],
|
107 |
+
outputs=[state, text],
|
108 |
+
).then(
|
109 |
+
fn=generate_cmap,
|
110 |
+
inputs=[state, max_num_concepts, max_num_links, max_num_sections],
|
111 |
+
outputs=[state, concept_map],
|
112 |
+
)
|
113 |
+
|
114 |
+
# Examples
|
115 |
+
gr.Examples(
|
116 |
+
examples=[
|
117 |
+
["tests/examples/bert.pdf"],
|
118 |
+
["tests/examples/attentionisallyouneed.pdf"],
|
119 |
+
["tests/examples/ashortsurvey.pdf"],
|
120 |
+
],
|
121 |
+
inputs=[paper_path],
|
122 |
+
)
|
123 |
+
|
124 |
+
|
125 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
paper2cmap==0.1.1
|
tests/examples/ashortsurvey.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:37a610e1a097d4365d35ec0b23baed1ff0de27a5a425fe1530a7c218cf63d50e
|
3 |
+
size 908967
|
tests/examples/attentionisallyouneed.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3c3baa34126e4df68d0d49b0c804be01975fca2d464b59a4cb1fcf2a937ce73f
|
3 |
+
size 860338
|
tests/examples/bert.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:77591680389138d960370f5476609fdeb0bee748d16538410961dc389665b190
|
3 |
+
size 591382
|