Spaces:
Runtime error
Runtime error
gamingflexer
commited on
Commit
·
db9914d
1
Parent(s):
9bccfe7
Add plagiarism checker and fetch papers data functionality
Browse files- src/app.py +73 -23
src/app.py
CHANGED
|
@@ -2,6 +2,9 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import logging
|
| 4 |
from scrapper.main import ArxivPaper
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
"""
|
| 7 |
author_obj = ArxivPaper("Andrew Ng")
|
|
@@ -10,26 +13,73 @@ paper_ids = author_obj.get_paper_id(paper_links)
|
|
| 10 |
author_obj.get_paper_details_batch(paper_ids=paper_ids, path="./data/papers")
|
| 11 |
"""
|
| 12 |
|
| 13 |
-
def plagiarism_checker(authors_name):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
"
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
)
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import logging
|
| 4 |
from scrapper.main import ArxivPaper
|
| 5 |
+
from config import *
|
| 6 |
+
from db.db_functions import get_correct_author_name, insert_papers_data, fetch_papers_data
|
| 7 |
+
from utils import compare_paper_ids
|
| 8 |
|
| 9 |
"""
|
| 10 |
author_obj = ArxivPaper("Andrew Ng")
|
|
|
|
| 13 |
author_obj.get_paper_details_batch(paper_ids=paper_ids, path="./data/papers")
|
| 14 |
"""
|
| 15 |
|
| 16 |
+
def plagiarism_checker(authors_name: str,number_of_results=5, progress=gr.Progress()):
|
| 17 |
+
progress(0.2, desc="Collecting Links")
|
| 18 |
+
author_obj = ArxivPaper(authors_name)
|
| 19 |
+
db_author_name = get_correct_author_name(authors_name)
|
| 20 |
+
paper_links = author_obj.get_results_google(number_of_results=number_of_results)
|
| 21 |
+
paper_ids = author_obj.get_paper_id(paper_links)
|
| 22 |
+
progress(0.4, desc="Collecting Papers")
|
| 23 |
+
if db_author_name is None:
|
| 24 |
+
print("No similar author found in the database")
|
| 25 |
+
author_obj.get_paper_details_batch(paper_ids=paper_ids, path="./data/papers")
|
| 26 |
+
local_saved_papers = os.path.join(os.getcwd(), "data", "papers", authors_name.replace(" ", "_"))
|
| 27 |
+
progress(0.6, desc="Making summary")
|
| 28 |
+
data_to_save = []
|
| 29 |
+
for paper in os.listdir(local_saved_papers):
|
| 30 |
+
paper_path = os.path.join(local_saved_papers, paper)
|
| 31 |
+
with open(paper_path, "r") as f:
|
| 32 |
+
data_to_save.append(f.read())
|
| 33 |
+
else:
|
| 34 |
+
print(f"Found similar author in the database: {db_author_name}")
|
| 35 |
+
data = fetch_papers_data(db_author_name)
|
| 36 |
+
reamining_paper_ids = compare_paper_ids(data,paper_ids)
|
| 37 |
+
progress(0.6, desc="Making summary")
|
| 38 |
+
data_to_save = []
|
| 39 |
+
if reamining_paper_ids != []:
|
| 40 |
+
author_obj.get_paper_details_batch(paper_ids=reamining_paper_ids, path="./data/papers")
|
| 41 |
+
local_saved_papers = os.path.join(os.getcwd(), "data", "papers", authors_name.replace(" ", "_"))
|
| 42 |
+
for paper in os.listdir(local_saved_papers):
|
| 43 |
+
paper_path = os.path.join(local_saved_papers, paper)
|
| 44 |
+
with open(paper_path, "r") as f:
|
| 45 |
+
data_to_save.append(f.read())
|
| 46 |
+
else:
|
| 47 |
+
print("All papers already present in the database")
|
| 48 |
+
|
| 49 |
+
progress(0.8, desc="Saving to Database")
|
| 50 |
+
insert_papers_data(data_to_save, authors_name)
|
| 51 |
+
return "Fetched Latest Papers"
|
| 52 |
+
|
| 53 |
+
def fetch_papers_data_df(authors_name: str, progress=gr.Progress()):
|
| 54 |
+
return pd.DataFrame(fetch_papers_data(authors_name))
|
| 55 |
+
|
| 56 |
+
with gr.Blocks() as demo:
|
| 57 |
+
|
| 58 |
+
with gr.Tab("Arxiv Plagiarism Fetcher & Save to DB"):
|
| 59 |
+
with gr.Row():
|
| 60 |
+
authors_name = gr.Textbox(label="Enter Author's Name")
|
| 61 |
+
number_of_results = gr.Number(label="Number of results - Min - 5")
|
| 62 |
+
submit_button_tab_1 = gr.Button("Start")
|
| 63 |
+
with gr.Row():
|
| 64 |
+
completed = gr.Textbox(label="Completed")
|
| 65 |
+
|
| 66 |
+
with gr.Tab("Get Papers Data"):
|
| 67 |
+
with gr.Row():
|
| 68 |
+
authors_name = gr.Textbox(label="Enter Author's Name")
|
| 69 |
+
submit_button_tab_2 = gr.Button("Start")
|
| 70 |
+
with gr.Row():
|
| 71 |
+
dataframe_output = gr.Dataframe(headers=['doi_no', 'title', 'summary', 'authors', 'year', 'pdf_link',
|
| 72 |
+
'references', 'categories', 'comment', 'journal_ref', 'source',
|
| 73 |
+
'primary_category', 'published'])
|
| 74 |
+
|
| 75 |
+
with gr.Tab("Arxiv Plagiarism Checker"):
|
| 76 |
+
with gr.Row():
|
| 77 |
+
authors_name = gr.Textbox(label="Enter Author's Name")
|
| 78 |
+
number_of_results = gr.Number(label="Number of results - Min - 5")
|
| 79 |
+
submit_button = gr.Button("Start")
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
submit_button_tab_1.click(fn=plagiarism_checker,inputs=[authors_name, number_of_results] ,outputs= completed)
|
| 83 |
+
submit_button_tab_2.click(fn=fetch_papers_data_df,inputs=[authors_name] ,outputs=dataframe_output)
|
| 84 |
+
|
| 85 |
+
demo.launch()
|