Update app.py
Browse files
app.py
CHANGED
@@ -113,12 +113,13 @@ def extract_chapter(file_object):
|
|
113 |
|
114 |
class Reviewer:
|
115 |
|
116 |
-
def __init__(self, api, api_base, paper_pdf, aspect, model_name, enable_rag):
|
117 |
self.api = api
|
118 |
self.api_base = api_base
|
119 |
self.aspect = aspect
|
120 |
self.paper_pdf = paper_pdf
|
121 |
self.model_name = model_name
|
|
|
122 |
self.enable_rag = enable_rag
|
123 |
# self.max_token_num = 50000
|
124 |
# self.encoding = tiktoken.get_encoding("gpt2")
|
@@ -325,12 +326,12 @@ Organize the result in JSON format as follows:
|
|
325 |
|
326 |
if self.enable_rag:
|
327 |
messages=[
|
328 |
-
{"role": "system", "content": f"Read the following content from several papers to gain knowledge in the relevant field. Using this knowledge, review a new scientific paper in this field. Based on existing research, identify the limitations of the 'Paper to Review'. Generate
|
329 |
{"role": "user", "content": text},
|
330 |
]
|
331 |
else:
|
332 |
messages=[
|
333 |
-
{"role": "system", "content": f"Read the following scientific paper and generate major limitations in this paper about its {self.aspect}. Do not include any limitation explicitly mentioned in the paper itself
|
334 |
{"role": "user", "content": text},
|
335 |
]
|
336 |
try:
|
@@ -345,7 +346,7 @@ Organize the result in JSON format as follows:
|
|
345 |
)
|
346 |
)
|
347 |
try:
|
348 |
-
limitations = json.loads(responses[0])["limitations"]
|
349 |
result = ""
|
350 |
limit_cnt = 1
|
351 |
for limitation in limitations:
|
@@ -367,7 +368,7 @@ Organize the result in JSON format as follows:
|
|
367 |
response_format={"type":"json_object"},
|
368 |
)
|
369 |
)
|
370 |
-
limitations = json.loads(responses[0])["limitations"]
|
371 |
result = ""
|
372 |
limit_cnt = 1
|
373 |
for limitation in limitations:
|
@@ -486,7 +487,7 @@ Organize the result in JSON format as follows:
|
|
486 |
break
|
487 |
return extracted_text, title, abstract
|
488 |
|
489 |
-
def main(api,api_base, paper_pdf, aspect, model_name, enable_rag):
|
490 |
start_time = time.time()
|
491 |
# print("key: ", PRIVATE_API_KEY, "\nbase: ", PRIVATE_API_BASE)
|
492 |
comments = ''
|
@@ -497,7 +498,7 @@ def main(api,api_base, paper_pdf, aspect, model_name, enable_rag):
|
|
497 |
output2 = "It looks like there's a missing API key or PDF input. Make sure you've provided the necessary information or uploaded the required file."
|
498 |
else:
|
499 |
try:
|
500 |
-
reviewer1 = Reviewer(api,api_base, paper_pdf, aspect, model_name, enable_rag)
|
501 |
comments, retrieved_content = reviewer1.review_by_chatgpt(paper_list=paper_pdf)
|
502 |
time_used = time.time() - start_time
|
503 |
output2 ="Processing Time:"+ str(round(time_used, 2)) +"seconds"
|
@@ -520,10 +521,10 @@ description = '''<div align='left'>
|
|
520 |
</div>
|
521 |
'''
|
522 |
|
523 |
-
inp = [gradio.Textbox(label="
|
524 |
value="",
|
525 |
type='password'),
|
526 |
-
gradio.Textbox(label="
|
527 |
value="https://api.openai.com/v1"),
|
528 |
|
529 |
gradio.File(label="Upload the PDF file of your paper (Make sure the PDF is fully uploaded before clicking Submit)",type="binary"),
|
@@ -531,10 +532,11 @@ inp = [gradio.Textbox(label="Input your API-key",
|
|
531 |
value="Methodology",
|
532 |
label="Select the aspect"),
|
533 |
gradio.Dropdown(["gpt-4o-mini","gpt-4o","Qwen/Qwen2.5-7B-Instruct-Turbo", "meta-llama/Meta-Llama-3-70B-Instruct-Turbo", "meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo"],
|
534 |
-
label="
|
535 |
value="gpt-4o-mini"),
|
536 |
-
gradio.
|
537 |
-
|
|
|
538 |
]
|
539 |
|
540 |
chat_reviewer_gui = gradio.Interface(fn=main,
|
|
|
113 |
|
114 |
class Reviewer:
|
115 |
|
116 |
+
def __init__(self, api, api_base, paper_pdf, aspect, model_name, limit_num, enable_rag):
|
117 |
self.api = api
|
118 |
self.api_base = api_base
|
119 |
self.aspect = aspect
|
120 |
self.paper_pdf = paper_pdf
|
121 |
self.model_name = model_name
|
122 |
+
self.limit_num = int(limit_num)
|
123 |
self.enable_rag = enable_rag
|
124 |
# self.max_token_num = 50000
|
125 |
# self.encoding = tiktoken.get_encoding("gpt2")
|
|
|
326 |
|
327 |
if self.enable_rag:
|
328 |
messages=[
|
329 |
+
{"role": "system", "content": f"Read the following content from several papers to gain knowledge in the relevant field. Using this knowledge, review a new scientific paper in this field. Based on existing research, identify the limitations of the 'Paper to Review'. Generate {str(self.limit_num)} major limitations related to its {self.aspect} in this paper. Do not include any limitation explicitly mentioned in the paper itself. Return only the limitations in the following JSON format: {{\"limitations\": <a list of limitations>"} ,
|
330 |
{"role": "user", "content": text},
|
331 |
]
|
332 |
else:
|
333 |
messages=[
|
334 |
+
{"role": "system", "content": f"Read the following scientific paper and generate {str(self.limit_num)} major limitations in this paper about its {self.aspect}. Do not include any limitation explicitly mentioned in the paper itself. Return only the limitations in the following JSON format: {{\"limitations\": <a list of limitations>"} ,
|
335 |
{"role": "user", "content": text},
|
336 |
]
|
337 |
try:
|
|
|
346 |
)
|
347 |
)
|
348 |
try:
|
349 |
+
limitations = json.loads(responses[0])["limitations"][:self.limit_num]
|
350 |
result = ""
|
351 |
limit_cnt = 1
|
352 |
for limitation in limitations:
|
|
|
368 |
response_format={"type":"json_object"},
|
369 |
)
|
370 |
)
|
371 |
+
limitations = json.loads(responses[0])["limitations"][:self.limit_num]
|
372 |
result = ""
|
373 |
limit_cnt = 1
|
374 |
for limitation in limitations:
|
|
|
487 |
break
|
488 |
return extracted_text, title, abstract
|
489 |
|
490 |
+
def main(api,api_base, paper_pdf, aspect, model_name, limit_num, enable_rag):
|
491 |
start_time = time.time()
|
492 |
# print("key: ", PRIVATE_API_KEY, "\nbase: ", PRIVATE_API_BASE)
|
493 |
comments = ''
|
|
|
498 |
output2 = "It looks like there's a missing API key or PDF input. Make sure you've provided the necessary information or uploaded the required file."
|
499 |
else:
|
500 |
try:
|
501 |
+
reviewer1 = Reviewer(api,api_base, paper_pdf, aspect, model_name, limit_num, enable_rag)
|
502 |
comments, retrieved_content = reviewer1.review_by_chatgpt(paper_list=paper_pdf)
|
503 |
time_used = time.time() - start_time
|
504 |
output2 ="Processing Time:"+ str(round(time_used, 2)) +"seconds"
|
|
|
521 |
</div>
|
522 |
'''
|
523 |
|
524 |
+
inp = [gradio.Textbox(label="Enter your API-key",
|
525 |
value="",
|
526 |
type='password'),
|
527 |
+
gradio.Textbox(label="Enter the base URL (ending with /v1). Skip this step if using the original OpenAI API.",
|
528 |
value="https://api.openai.com/v1"),
|
529 |
|
530 |
gradio.File(label="Upload the PDF file of your paper (Make sure the PDF is fully uploaded before clicking Submit)",type="binary"),
|
|
|
532 |
value="Methodology",
|
533 |
label="Select the aspect"),
|
534 |
gradio.Dropdown(["gpt-4o-mini","gpt-4o","Qwen/Qwen2.5-7B-Instruct-Turbo", "meta-llama/Meta-Llama-3-70B-Instruct-Turbo", "meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo"],
|
535 |
+
label="Select the model name",
|
536 |
value="gpt-4o-mini"),
|
537 |
+
gradio.Textbox(label="Enter the number of limitations to generate.",
|
538 |
+
value="3"),
|
539 |
+
gradio.Checkbox(label="Enable RAG", value=False),
|
540 |
]
|
541 |
|
542 |
chat_reviewer_gui = gradio.Interface(fn=main,
|