raannakasturi commited on
Commit
cd350ce
·
1 Parent(s): 6e331a2

Refactor app.py to remove unused functions and streamline package installations; update requirements.txt to reflect necessary dependencies.

Browse files
Files changed (2) hide show
  1. app.py +28 -91
  2. requirements.txt +2 -3
app.py CHANGED
@@ -1,92 +1,29 @@
1
- import json
2
  import os
3
- import pdf2doi
4
- import gradio as gr
5
- import requests
6
- import html
7
-
8
- def download_pdf(url):
9
- file_path = f"{url.split('/')[-1]}.pdf"
10
- response = requests.get(url)
11
- with open(file_path, 'wb') as file:
12
- file.write(response.content)
13
- return file_path
14
-
15
- import json
16
-
17
- def get_doi(pdf_path):
18
- pdf2doi.config.set('verbose', False)
19
- results = pdf2doi.pdf2doi(pdf_path)
20
- validation_info = results.get('validation_info', {})
21
- if isinstance(validation_info, str):
22
- try:
23
- validation_info = json.loads(validation_info) # Convert JSON string to dic
24
- except json.JSONDecodeError as e:
25
- print(f"Error decoding JSON: {e}")
26
- return None, None, None
27
- if not isinstance(validation_info, dict):
28
- print("Validation info is not a dictionary")
29
- return None, None, None
30
- doi = validation_info.get('DOI', None)
31
- title = validation_info.get('title', None)
32
- url = validation_info.get('URL', None)
33
- return doi, title, url
34
-
35
- def get_paper_data(doi):
36
- api_url = f"https://api.citeas.org/product/{doi}"
37
- response = requests.get(api_url)
38
- return response.json()
39
-
40
- def main(pdf_url):
41
- pdf_path = download_pdf(pdf_url)
42
- doi, title, url = get_doi(pdf_path)
43
- if doi is None:
44
- return json.dumps({"error": "DOI not found"}, indent=4)
45
- paper_data = get_paper_data(doi)
46
- if not paper_data:
47
- return json.dumps({"error": "Paper data not found"}, indent=4)
48
- citation_text = None
49
- for citation in paper_data.get('citations', []):
50
- if citation.get('style_shortname') == 'apa':
51
- citation_text = citation.get('citation')
52
- break
53
- title = title or paper_data.get('name')
54
- url = url or f"https://doi.org/{doi}"
55
- if citation_text:
56
- citation_text = citation_text.encode('utf-8').decode('utf-8')
57
- citation_text = html.unescape(
58
- citation_text.replace("<i>", "").replace("</i>", "").replace("\u2026", "...").replace("\n", " ")
59
- )
60
- else:
61
- citation_text = "Citation not found"
62
- data = {
63
- "doi": doi,
64
- "title": title if title else "Title not found",
65
- "citation_text": citation_text,
66
- "url": url
67
- }
68
- os.remove(pdf_path)
69
- return json.dumps(data, ensure_ascii=False, indent=4)
70
-
71
-
72
- theme = gr.themes.Soft(
73
- primary_hue="purple",
74
- secondary_hue="cyan",
75
- neutral_hue="slate",
76
- font=[
77
- gr.themes.GoogleFont("Syne"),
78
- gr.themes.GoogleFont("Poppins"),
79
- gr.themes.GoogleFont("Poppins"),
80
- gr.themes.GoogleFont("Poppins")
81
- ],
82
- )
83
-
84
- with gr.Blocks(theme=theme) as app:
85
- with gr.Row():
86
- pdf_path = gr.Textbox(lines=1, label="PDF URL", placeholder="Enter the URL of the PDF")
87
- doi_data = gr.Textbox(lines=7, label="DOI Data", placeholder="DOI data will be displayed here", show_copy_button=True)
88
- get_data = gr.Button(value="Get DOI Data", variant='primary')
89
-
90
- get_data.click(main, inputs=[pdf_path], outputs=[doi_data], api_name="getDOIData")
91
-
92
- app.queue(default_concurrency_limit=250).launch()
 
 
1
  import os
2
+ import sys
3
+
4
+
5
+ os.system('pip uninstall -y mineru')
6
+ os.system('pip install git+https://gitee.com/myhloli/MinerU.git@dev -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple')
7
+ os.system('pip install -U docvortex -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple')
8
+ os.system('pip uninstall -y onnxruntime onnxruntime-gpu')
9
+ os.system('pip install onnxruntime-gpu==1.23.2 -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple')
10
+ os.system('pip uninstall -y flash-attn scikit-learn scipy')
11
+
12
+ # Force HF model source inside the Space; avoid auto-probe fallback to modelscope.
13
+ os.environ.setdefault("MINERU_MODEL_SOURCE", "modelscope")
14
+ # First cold start downloads models before the managed API server becomes healthy.
15
+ os.environ.setdefault("MINERU_LOCAL_API_STARTUP_TIMEOUT_SECONDS", "1800")
16
+ os.environ.setdefault("GRADIO_SSR_MODE", "False")
17
+ os.environ['MINERU_PDF_RENDER_TIMEOUT'] = "10"
18
+
19
+ from mineru.kit.commands.webui import main
20
+
21
+ if __name__ == "__main__":
22
+ sys.argv = [
23
+ "mineru-webui",
24
+ "--server-name", "0.0.0.0",
25
+ "--server-port", "7860",
26
+ "--max-pages", "20",
27
+ "--preload-models",
28
+ ]
29
+ main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,3 +1,2 @@
1
- pdf2doi
2
- gradio
3
- requests
 
1
+ mineru[torch]>=4.0.0,<5
2
+ vllm==0.19.1