Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from huggingface_hub import hf_hub_download
|
| 2 |
import re
|
| 3 |
from PIL import Image
|
|
@@ -50,7 +93,7 @@ def predict(image):
|
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
-
def inference(pdf_file, pdf_link
|
| 54 |
if pdf_file is None:
|
| 55 |
if pdf_link == '':
|
| 56 |
print("No file is uploaded and No link is provided")
|
|
@@ -69,13 +112,12 @@ def inference(pdf_file, pdf_link, file_btn):
|
|
| 69 |
|
| 70 |
|
| 71 |
content = sequence.replace(r'\(', '$').replace(r'\)', '$').replace(r'\[', '$$').replace(r'\]', '$$')
|
| 72 |
-
|
| 73 |
-
if file_btn:
|
| 74 |
-
with open(f"{os.getcwd()}/output.txt","w+") as f:
|
| 75 |
f.write(content)
|
| 76 |
f.close()
|
| 77 |
-
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
css = """
|
|
@@ -101,8 +143,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 101 |
with gr.Row(equal_height=True):
|
| 102 |
pdf_file = gr.File(label='PDF π', file_count='single', scale=1)
|
| 103 |
pdf_link = gr.Textbox(placeholder='Enter an arxiv link here', label='Link to Paperπ', scale=1)
|
| 104 |
-
with gr.Row():
|
| 105 |
-
file_btn = gr.Checkbox(label='Download output as file π')
|
| 106 |
with gr.Row():
|
| 107 |
btn = gr.Button('Run Nougat π«')
|
| 108 |
with gr.Row():
|
|
@@ -113,17 +153,17 @@ with gr.Blocks(css=css) as demo:
|
|
| 113 |
parsed_output = gr.Markdown(elem_id='mkd', value='Output Text π')
|
| 114 |
output_file = gr.File(file_types = ["txt"], label="Output File π")
|
| 115 |
|
| 116 |
-
btn.click(inference, [pdf_file, pdf_link
|
| 117 |
clr.click(lambda : (gr.update(value=None),
|
| 118 |
gr.update(value=None),
|
| 119 |
gr.update(value=None),
|
| 120 |
gr.update(value=None)),
|
| 121 |
[],
|
| 122 |
-
[pdf_file, pdf_link,
|
| 123 |
)
|
| 124 |
gr.Examples(
|
| 125 |
-
[["nougat.pdf", ""
|
| 126 |
-
inputs = [pdf_file, pdf_link
|
| 127 |
outputs = [parsed_output, output_file],
|
| 128 |
fn=inference,
|
| 129 |
cache_examples=True,
|
|
@@ -133,4 +173,4 @@ with gr.Blocks(css=css) as demo:
|
|
| 133 |
|
| 134 |
|
| 135 |
demo.queue()
|
| 136 |
-
demo.launch(debug=True)
|
|
|
|
| 1 |
+
Hugging Face's logo
|
| 2 |
+
Hugging Face
|
| 3 |
+
Search models, datasets, users...
|
| 4 |
+
Models
|
| 5 |
+
Datasets
|
| 6 |
+
Spaces
|
| 7 |
+
Docs
|
| 8 |
+
Solutions
|
| 9 |
+
Pricing
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Click here to log in through Single Sign-On to view activity within the huggingface org.
|
| 14 |
+
|
| 15 |
+
Spaces:
|
| 16 |
+
|
| 17 |
+
merve
|
| 18 |
+
/
|
| 19 |
+
nougat-transformers
|
| 20 |
+
|
| 21 |
+
like
|
| 22 |
+
0
|
| 23 |
+
|
| 24 |
+
App
|
| 25 |
+
Files
|
| 26 |
+
Community
|
| 27 |
+
Settings
|
| 28 |
+
nougat-transformers
|
| 29 |
+
/
|
| 30 |
+
app.py
|
| 31 |
+
merve's picture
|
| 32 |
+
merve
|
| 33 |
+
HF STAFF
|
| 34 |
+
Update app.py
|
| 35 |
+
7c259fa
|
| 36 |
+
7 minutes ago
|
| 37 |
+
raw
|
| 38 |
+
history
|
| 39 |
+
blame
|
| 40 |
+
edit
|
| 41 |
+
delete
|
| 42 |
+
No virus
|
| 43 |
+
4.31 kB
|
| 44 |
from huggingface_hub import hf_hub_download
|
| 45 |
import re
|
| 46 |
from PIL import Image
|
|
|
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
+
def inference(pdf_file, pdf_link):
|
| 97 |
if pdf_file is None:
|
| 98 |
if pdf_link == '':
|
| 99 |
print("No file is uploaded and No link is provided")
|
|
|
|
| 112 |
|
| 113 |
|
| 114 |
content = sequence.replace(r'\(', '$').replace(r'\)', '$').replace(r'\[', '$$').replace(r'\]', '$$')
|
| 115 |
+
with open(f"{os.getcwd()}/output.md","w+") as f:
|
|
|
|
|
|
|
| 116 |
f.write(content)
|
| 117 |
f.close()
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
return content, f"{os.getcwd()}/output.md"
|
| 121 |
|
| 122 |
|
| 123 |
css = """
|
|
|
|
| 143 |
with gr.Row(equal_height=True):
|
| 144 |
pdf_file = gr.File(label='PDF π', file_count='single', scale=1)
|
| 145 |
pdf_link = gr.Textbox(placeholder='Enter an arxiv link here', label='Link to Paperπ', scale=1)
|
|
|
|
|
|
|
| 146 |
with gr.Row():
|
| 147 |
btn = gr.Button('Run Nougat π«')
|
| 148 |
with gr.Row():
|
|
|
|
| 153 |
parsed_output = gr.Markdown(elem_id='mkd', value='Output Text π')
|
| 154 |
output_file = gr.File(file_types = ["txt"], label="Output File π")
|
| 155 |
|
| 156 |
+
btn.click(inference, [pdf_file, pdf_link], [parsed_output, output_file])
|
| 157 |
clr.click(lambda : (gr.update(value=None),
|
| 158 |
gr.update(value=None),
|
| 159 |
gr.update(value=None),
|
| 160 |
gr.update(value=None)),
|
| 161 |
[],
|
| 162 |
+
[pdf_file, pdf_link, parsed_output, output_file]
|
| 163 |
)
|
| 164 |
gr.Examples(
|
| 165 |
+
[["nougat.pdf", ""], [None, "https://arxiv.org/pdf/2308.08316.pdf"]],
|
| 166 |
+
inputs = [pdf_file, pdf_link],
|
| 167 |
outputs = [parsed_output, output_file],
|
| 168 |
fn=inference,
|
| 169 |
cache_examples=True,
|
|
|
|
| 173 |
|
| 174 |
|
| 175 |
demo.queue()
|
| 176 |
+
demo.launch(debug=True)
|