xy63 commited on
Commit
f2be85a
·
verified ·
1 Parent(s): 9616d2d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +263 -256
app.py CHANGED
@@ -1,256 +1,263 @@
1
- import gradio as gr
2
- import spaces
3
- from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
4
- import torch
5
- from threading import Thread
6
-
7
- from marker.convert import convert_single_pdf
8
- from marker.output import markdown_exists, save_markdown, get_markdown_filepath
9
- from marker.pdf.utils import find_filetype
10
- from marker.pdf.extract_text import get_length_of_text
11
- from marker.models import load_all_models
12
- from marker.settings import settings
13
- from marker.logger import configure_logging
14
- from surya.settings import settings as surya_settings
15
- import traceback
16
-
17
-
18
- # marker
19
- configure_logging()
20
- MAX_PAGES = 20
21
- MIN_LENGTH=200
22
- settings.EXTRACT_IMAGES = False
23
- settings.DEBUG = False
24
- settings.PDFTEXT_CPU_WORKERS = 1
25
- settings.DETECTOR_POSTPROCESSING_CPU_WORKERS = 1
26
- settings.OCR_PARALLEL_WORKERS = 1
27
- surya_settings.IN_STREAMLIT = True
28
-
29
- model_refs = load_all_models()
30
- metadata = {}
31
-
32
- # prepare LLM
33
- model_name = "maxidl/Llama-OpenReviewer-8B"
34
- model = AutoModelForCausalLM.from_pretrained(
35
- model_name,
36
- torch_dtype=torch.bfloat16,
37
- device_map="auto"
38
- )
39
- tokenizer = AutoTokenizer.from_pretrained(model_name)
40
- streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, decode_kwargs=dict(skip_special_tokens=True))
41
-
42
- # Define prompts
43
- SYSTEM_PROMPT_TEMPLATE = """You are an expert reviewer for AI conferences. You follow best practices and review papers according to the reviewer guidelines.
44
-
45
- Reviewer guidelines:
46
- 1. Read the paper: Its important to carefully read through the entire paper, and to look up any related work and citations that will help you comprehensively evaluate it. Be sure to give yourself sufficient time for this step.
47
- 2. While reading, consider the following:
48
- - Objective of the work: What is the goal of the paper? Is it to better address a known application or problem, draw attention to a new application or problem, or to introduce and/or explain a new theoretical finding? A combination of these? Different objectives will require different considerations as to potential value and impact.
49
- - Strong points: is the submission clear, technically correct, experimentally rigorous, reproducible, does it present novel findings (e.g. theoretically, algorithmically, etc.)?
50
- - Weak points: is it weak in any of the aspects listed in b.?
51
- - Be mindful of potential biases and try to be open-minded about the value and interest a paper can hold for the community, even if it may not be very interesting for you.
52
- 3. Answer four key questions for yourself, to make a recommendation to Accept or Reject:
53
- - What is the specific question and/or problem tackled by the paper?
54
- - Is the approach well motivated, including being well-placed in the literature?
55
- - Does the paper support the claims? This includes determining if results, whether theoretical or empirical, are correct and if they are scientifically rigorous.
56
- - What is the significance of the work? Does it contribute new knowledge and sufficient value to the community? Note, this does not necessarily require state-of-the-art results. Submissions bring value to the community when they convincingly demonstrate new, relevant, impactful knowledge (incl., empirical, theoretical, for practitioners, etc).
57
- 4. Write your review including the following information:
58
- - Summarize what the paper claims to contribute. Be positive and constructive.
59
- - List strong and weak points of the paper. Be as comprehensive as possible.
60
- - Clearly state your initial recommendation (accept or reject) with one or two key reasons for this choice.
61
- - Provide supporting arguments for your recommendation.
62
- - Ask questions you would like answered by the authors to help you clarify your understanding of the paper and provide the additional evidence you need to be confident in your assessment.
63
- - Provide additional feedback with the aim to improve the paper. Make it clear that these points are here to help, and not necessarily part of your decision assessment.
64
-
65
- Your write reviews in markdown format. Your reviews contain the following sections:
66
-
67
- # Review
68
-
69
- {review_fields}
70
-
71
- Your response must only contain the review in markdown format with sections as defined above.
72
- """
73
-
74
- USER_PROMPT_TEMPLATE = """Review the following paper:
75
-
76
- {paper_text}
77
- """
78
-
79
- # For now, use fixed review fields
80
- REVIEW_FIELDS = """## Summary
81
- Briefly summarize the paper and its contributions. This is not the place to critique the paper; the authors should generally agree with a well-written summary.
82
-
83
- ## Soundness
84
- Please assign the paper a numerical rating on the following scale to indicate the soundness of the technical claims, experimental and research methodology and on whether the central claims of the paper are adequately supported with evidence. Choose from the following:
85
- 4: excellent
86
- 3: good
87
- 2: fair
88
- 1: poor
89
-
90
- ## Presentation
91
- Please assign the paper a numerical rating on the following scale to indicate the quality of the presentation. This should take into account the writing style and clarity, as well as contextualization relative to prior work. Choose from the following:
92
- 4: excellent
93
- 3: good
94
- 2: fair
95
- 1: poor
96
-
97
- ## Contribution
98
- Please assign the paper a numerical rating on the following scale to indicate the quality of the overall contribution this paper makes to the research area being studied. Are the questions being asked important? Does the paper bring a significant originality of ideas and/or execution? Are the results valuable to share with the broader ICLR community? Choose from the following:
99
- 4: excellent
100
- 3: good
101
- 2: fair
102
- 1: poor
103
-
104
- ## Strengths
105
- A substantive assessment of the strengths of the paper, touching on each of the following dimensions: originality, quality, clarity, and significance. We encourage reviewers to be broad in their definitions of originality and significance. For example, originality may arise from a new definition or problem formulation, creative combinations of existing ideas, application to a new domain, or removing limitations from prior results.
106
-
107
- ## Weaknesses
108
- A substantive assessment of the weaknesses of the paper. Focus on constructive and actionable insights on how the work could improve towards its stated goals. Be specific, avoid generic remarks. For example, if you believe the contribution lacks novelty, provide references and an explanation as evidence; if you believe experiments are insufficient, explain why and exactly what is missing, etc.
109
-
110
- ## Questions
111
- Please list up and carefully describe any questions and suggestions for the authors. Think of the things where a response from the author can change your opinion, clarify a confusion or address a limitation. This is important for a productive rebuttal and discussion phase with the authors.
112
-
113
- ## Flag For Ethics Review
114
- If there are ethical issues with this paper, please flag the paper for an ethics review and select area of expertise that would be most useful for the ethics reviewer to have. Please select all that apply. Choose from the following:
115
- No ethics review needed.
116
- Yes, Discrimination / bias / fairness concerns
117
- Yes, Privacy, security and safety
118
- Yes, Legal compliance (e.g., GDPR, copyright, terms of use)
119
- Yes, Potentially harmful insights, methodologies and applications
120
- Yes, Responsible research practice (e.g., human subjects, data release)
121
- Yes, Research integrity issues (e.g., plagiarism, dual submission)
122
- Yes, Unprofessional behaviors (e.g., unprofessional exchange between authors and reviewers)
123
- Yes, Other reasons (please specify below)
124
-
125
- ## Details Of Ethics Concerns
126
- Please provide details of your concerns.
127
-
128
- ## Rating
129
- Please provide an "overall score" for this submission. Choose from the following:
130
- 1: strong reject
131
- 3: reject, not good enough
132
- 5: marginally below the acceptance threshold
133
- 6: marginally above the acceptance threshold
134
- 8: accept, good paper
135
- 10: strong accept, should be highlighted at the conference
136
-
137
-
138
- """
139
-
140
- # functions
141
- def create_messages(review_fields, paper_text):
142
- messages = [
143
- {"role": "system", "content": SYSTEM_PROMPT_TEMPLATE.format(review_fields=review_fields)},
144
- {"role": "user", "content": USER_PROMPT_TEMPLATE.format(paper_text=paper_text)},
145
- ]
146
- return messages
147
-
148
- @spaces.GPU()
149
- def convert_file(filepath):
150
- full_text, images, out_metadata = convert_single_pdf(
151
- filepath, model_refs, metadata=metadata, max_pages=MAX_PAGES
152
- )
153
- return full_text
154
-
155
- def process_file(file):
156
- print(file.name)
157
- filepath = file.name
158
- try:
159
- if MIN_LENGTH:
160
- filetype = find_filetype(filepath)
161
- if filetype == "other":
162
- raise ValueError()
163
-
164
- length = get_length_of_text(filepath)
165
- if length < MIN_LENGTH:
166
- raise ValueError()
167
- paper_text = convert_file(filepath)
168
- paper_text = paper_text.strip()
169
- if not len(paper_text) > MIN_LENGTH:
170
- raise ValueError()
171
- except spaces.zero.gradio.HTMLError as e:
172
- print(e)
173
- return "Error. GPU quota exceeded. Please return later."
174
- # except gradio.exceptions.Error as e:
175
- # if 'GPU task aborted' in str(e):
176
- # print(e)
177
- # return 'GPU task aborted'
178
- except Exception as e:
179
- print(traceback.format_exc())
180
- print(f"Error converting {filepath}: {e}")
181
- return "Error processing pdf"
182
- return paper_text
183
-
184
-
185
- @spaces.GPU(duration=90)
186
- def generate(paper_text, review_template):
187
- messages = create_messages(review_template, paper_text)
188
- input_ids = tokenizer.apply_chat_template(
189
- messages,
190
- add_generation_prompt=True,
191
- return_tensors='pt'
192
- ).to(model.device)
193
- print(f"input_ids shape: {input_ids.shape}")
194
- generation_kwargs = dict(input_ids=input_ids, streamer=streamer, max_new_tokens=4096, do_sample=True, temperature=0.6, top_p=0.9)
195
- thread = Thread(target=model.generate, kwargs=generation_kwargs)
196
- thread.start()
197
- generated_text = ""
198
- for new_text in streamer:
199
- generated_text += new_text
200
- yield generated_text.replace("<|eot_id|>", "")
201
-
202
-
203
-
204
- # ui
205
- #8C1B13 red
206
- #4D8093 blue
207
- #767676 med grey
208
- #EFECE3 light grey
209
- #DDDDDD silver below red
210
- #FFFDFA white
211
-
212
- title = """<h1 align="center">OpenReviewer</h1>
213
- <div align="center">Using <a href="https://huggingface.co/maxidl/Llama-OpenReviewer-8B" target="_blank"><code>Llama-OpenReviewer-8B</code></a> - Built with Llama</div>
214
- """
215
-
216
- description = """This is an online demo featuring [Llama-OpenReviewer-8B](https://huggingface.co/maxidl/Llama-OpenReviewer-8B), a large language model that generates high-quality reviews for machine learning and AI papers.
217
-
218
- ## Demo Guidelines
219
-
220
- 1. Upload you paper as a pdf file. Alternatively you can paste the full text of your paper in markdown format below. We do **not** store your data. User data is kept in ephemeral storage during processing.
221
-
222
- 2. Once you upload a pdf it will be converted to markdown. This takes some time as it runs multiple transformer models to parse the layout and extract text and tables. Checkout [marker](https://github.com/VikParuchuri/marker/tree/master) for details.
223
-
224
- 3. Having obtained a markdown version of your paper, you can now click *Generate Review*.
225
-
226
- Take a look at the Review Template to properly interpret the generated review. You can also change the review template before generating in case you want to generate a review with a different schema and aspects.
227
-
228
- To obtain more than one review, just generate again.
229
-
230
- **GPU quota:** If exceeded, either sign in with your HF account or come back later. Your quota has a half-life of 2 hours.
231
-
232
- """
233
-
234
- theme = gr.themes.Default(primary_hue="gray", secondary_hue="blue", neutral_hue="slate")
235
- with gr.Blocks(theme=theme) as demo:
236
- title = gr.HTML(title)
237
- description = gr.Markdown(description)
238
- file_input = gr.File(file_types=[".pdf"], file_count="single")
239
- paper_text_field= gr.Textbox("Upload a pdf or paste the full text of your paper in markdown format here.", label="Paper Text", lines=20, max_lines=20, autoscroll=False)
240
- with gr.Accordion("Review Template", open=False):
241
- review_template_description = gr.Markdown("We use the ICLR 2025 review template by default, but you can modify the template below as you like.")
242
- review_template_field = gr.Textbox(label=" ",lines=20, max_lines=20, autoscroll=False, value=REVIEW_FIELDS)
243
- generate_button = gr.Button("Generate Review", interactive=not paper_text_field)
244
- file_input.upload(process_file, file_input, paper_text_field)
245
- paper_text_field.change(lambda text: gr.update(interactive=True) if len(text) > 200 else gr.update(interactive=False), paper_text_field, generate_button)
246
-
247
- review_field = gr.Markdown("\n\n\n\n\n", label="Review")
248
- generate_button.click(fn=lambda: gr.update(interactive=False), inputs=None, outputs=generate_button).then(generate, [paper_text_field, review_template_field], review_field).then(fn=lambda: gr.update(interactive=True), inputs=None, outputs=generate_button)
249
-
250
- demo.title = "OpenReviewer"
251
-
252
-
253
-
254
-
255
- if __name__ == "__main__":
256
- demo.launch()
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import spaces
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
4
+ import torch
5
+ from threading import Thread
6
+
7
+ from marker.convert import convert_single_pdf
8
+ from marker.output import markdown_exists, save_markdown, get_markdown_filepath
9
+ from marker.pdf.utils import find_filetype
10
+ from marker.pdf.extract_text import get_length_of_text
11
+ from marker.models import load_all_models
12
+ from marker.settings import settings
13
+ from marker.logger import configure_logging
14
+ from surya.settings import settings as surya_settings
15
+ import traceback
16
+
17
+
18
+ # marker
19
+ configure_logging()
20
+ MAX_PAGES = 20
21
+ MIN_LENGTH=200
22
+ settings.EXTRACT_IMAGES = False
23
+ settings.DEBUG = False
24
+ settings.PDFTEXT_CPU_WORKERS = 1
25
+ settings.DETECTOR_POSTPROCESSING_CPU_WORKERS = 1
26
+ settings.OCR_PARALLEL_WORKERS = 1
27
+ surya_settings.IN_STREAMLIT = True
28
+
29
+ model_refs = load_all_models()
30
+ metadata = {}
31
+
32
+ # prepare LLM
33
+ model_name = "maxidl/Llama-OpenReviewer-8B"
34
+ model = AutoModelForCausalLM.from_pretrained(
35
+ model_name,
36
+ torch_dtype=torch.bfloat16,
37
+ device_map="auto"
38
+ )
39
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
40
+ streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, decode_kwargs=dict(skip_special_tokens=True))
41
+
42
+ # Define prompts
43
+ SYSTEM_PROMPT_TEMPLATE = """You are an expert reviewer for AI conferences. You follow best practices and review papers according to the reviewer guidelines.
44
+
45
+ Reviewer guidelines:
46
+ 1. Read the paper: It's important to carefully read through the entire paper, and to look up any related work and citations that will help you comprehensively evaluate it. Be sure to give yourself sufficient time for this step.
47
+ 2. While reading, consider the following:
48
+ - Objective of the work: What is the goal of the paper? Is it to better address a known application or problem, draw attention to a new application or problem, or to introduce and/or explain a new theoretical finding? A combination of these? Different objectives will require different considerations as to potential value and impact.
49
+ - Strong points: is the submission clear, technically correct, experimentally rigorous, reproducible, does it present novel findings (e.g. theoretically, algorithmically, etc.)?
50
+ - Weak points: is it weak in any of the aspects listed in b.?
51
+ - Be mindful of potential biases and try to be open-minded about the value and interest a paper can hold for the community, even if it may not be very interesting for you.
52
+ 3. Answer four key questions for yourself, to make a recommendation to Accept or Reject:
53
+ - What is the specific question and/or problem tackled by the paper?
54
+ - Is the approach well motivated, including being well-placed in the literature?
55
+ - Does the paper support the claims? This includes determining if results, whether theoretical or empirical, are correct and if they are scientifically rigorous.
56
+ - What is the significance of the work? Does it contribute new knowledge and sufficient value to the community? Note, this does not necessarily require state-of-the-art results. Submissions bring value to the community when they convincingly demonstrate new, relevant, impactful knowledge (incl., empirical, theoretical, for practitioners, etc).
57
+ 4. Write your review including the following information:
58
+ - Summarize what the paper claims to contribute. Be positive and constructive.
59
+ - List strong and weak points of the paper. Be as comprehensive as possible.
60
+ - Clearly state your initial recommendation (accept or reject) with one or two key reasons for this choice.
61
+ - Provide supporting arguments for your recommendation.
62
+ - Ask questions you would like answered by the authors to help you clarify your understanding of the paper and provide the additional evidence you need to be confident in your assessment.
63
+ - Provide additional feedback with the aim to improve the paper. Make it clear that these points are here to help, and not necessarily part of your decision assessment.
64
+
65
+ Your write reviews in markdown format. Your reviews contain the following sections:
66
+
67
+ # Review
68
+
69
+ {review_fields}
70
+
71
+ Your response must only contain the review in markdown format with sections as defined above.
72
+ """
73
+
74
+ USER_PROMPT_TEMPLATE = """Review the following paper:
75
+
76
+ {paper_text}
77
+ """
78
+
79
+ # For now, use fixed review fields
80
+ REVIEW_FIELDS = """## Summary
81
+ Briefly summarize the paper and its contributions. This is not the place to critique the paper; the authors should generally agree with a well-written summary.
82
+
83
+ ## Soundness
84
+ Please assign the paper a numerical rating on the following scale to indicate the soundness of the technical claims, experimental and research methodology and on whether the central claims of the paper are adequately supported with evidence. Choose from the following:
85
+ 4: excellent
86
+ 3: good
87
+ 2: fair
88
+ 1: poor
89
+
90
+ **Justification for Soundness Rating:** Please provide specific reasons for your soundness score, explaining which aspects of the technical claims, methodology, or evidence support your rating.
91
+
92
+ ## Presentation
93
+ Please assign the paper a numerical rating on the following scale to indicate the quality of the presentation. This should take into account the writing style and clarity, as well as contextualization relative to prior work. Choose from the following:
94
+ 4: excellent
95
+ 3: good
96
+ 2: fair
97
+ 1: poor
98
+
99
+ **Justification for Presentation Rating:** Please explain your presentation score by addressing specific aspects of writing clarity, organization, figure quality, and how well the work is positioned within existing literature.
100
+
101
+ ## Contribution
102
+ Please assign the paper a numerical rating on the following scale to indicate the quality of the overall contribution this paper makes to the research area being studied. Are the questions being asked important? Does the paper bring a significant originality of ideas and/or execution? Are the results valuable to share with the broader ICLR community? Choose from the following:
103
+ 4: excellent
104
+ 3: good
105
+ 2: fair
106
+ 1: poor
107
+
108
+ **Justification for Contribution Rating:** Please justify your contribution score by explaining the significance of the research questions, the originality of the approach, and the potential impact on the field.
109
+
110
+ ## Strengths
111
+ A substantive assessment of the strengths of the paper, touching on each of the following dimensions: originality, quality, clarity, and significance. We encourage reviewers to be broad in their definitions of originality and significance. For example, originality may arise from a new definition or problem formulation, creative combinations of existing ideas, application to a new domain, or removing limitations from prior results.
112
+
113
+ ## Weaknesses
114
+ A substantive assessment of the weaknesses of the paper. Focus on constructive and actionable insights on how the work could improve towards its stated goals. Be specific, avoid generic remarks. For example, if you believe the contribution lacks novelty, provide references and an explanation as evidence; if you believe experiments are insufficient, explain why and exactly what is missing, etc.
115
+
116
+ ## Questions
117
+ Please list up and carefully describe any questions and suggestions for the authors. Think of the things where a response from the author can change your opinion, clarify a confusion or address a limitation. This is important for a productive rebuttal and discussion phase with the authors.
118
+
119
+ ## Flag For Ethics Review
120
+ If there are ethical issues with this paper, please flag the paper for an ethics review and select area of expertise that would be most useful for the ethics reviewer to have. Please select all that apply. Choose from the following:
121
+ No ethics review needed.
122
+ Yes, Discrimination / bias / fairness concerns
123
+ Yes, Privacy, security and safety
124
+ Yes, Legal compliance (e.g., GDPR, copyright, terms of use)
125
+ Yes, Potentially harmful insights, methodologies and applications
126
+ Yes, Responsible research practice (e.g., human subjects, data release)
127
+ Yes, Research integrity issues (e.g., plagiarism, dual submission)
128
+ Yes, Unprofessional behaviors (e.g., unprofessional exchange between authors and reviewers)
129
+ Yes, Other reasons (please specify below)
130
+
131
+ ## Details Of Ethics Concerns
132
+ Please provide details of your concerns.
133
+
134
+ ## Rating
135
+ Please provide an "overall score" for this submission. Choose from the following:
136
+ 1: strong reject
137
+ 3: reject, not good enough
138
+ 5: marginally below the acceptance threshold
139
+ 6: marginally above the acceptance threshold
140
+ 8: accept, good paper
141
+ 10: strong accept, should be highlighted at the conference
142
+
143
+ **Justification for Overall Rating:** Please provide a comprehensive justification for your overall rating, synthesizing the key strengths and weaknesses that led to this decision. Explain how you weighted different aspects of the paper in arriving at your final score.
144
+
145
+ """
146
+
147
+ # functions
148
+ def create_messages(review_fields, paper_text):
149
+ messages = [
150
+ {"role": "system", "content": SYSTEM_PROMPT_TEMPLATE.format(review_fields=review_fields)},
151
+ {"role": "user", "content": USER_PROMPT_TEMPLATE.format(paper_text=paper_text)},
152
+ ]
153
+ return messages
154
+
155
+ @spaces.GPU()
156
+ def convert_file(filepath):
157
+ full_text, images, out_metadata = convert_single_pdf(
158
+ filepath, model_refs, metadata=metadata, max_pages=MAX_PAGES
159
+ )
160
+ return full_text
161
+
162
+ def process_file(file):
163
+ print(file.name)
164
+ filepath = file.name
165
+ try:
166
+ if MIN_LENGTH:
167
+ filetype = find_filetype(filepath)
168
+ if filetype == "other":
169
+ raise ValueError()
170
+
171
+ length = get_length_of_text(filepath)
172
+ if length < MIN_LENGTH:
173
+ raise ValueError()
174
+ paper_text = convert_file(filepath)
175
+ paper_text = paper_text.strip()
176
+ if not len(paper_text) > MIN_LENGTH:
177
+ raise ValueError()
178
+ except spaces.zero.gradio.HTMLError as e:
179
+ print(e)
180
+ return "Error. GPU quota exceeded. Please return later."
181
+ # except gradio.exceptions.Error as e:
182
+ # if 'GPU task aborted' in str(e):
183
+ # print(e)
184
+ # return 'GPU task aborted'
185
+ except Exception as e:
186
+ print(traceback.format_exc())
187
+ print(f"Error converting {filepath}: {e}")
188
+ return "Error processing pdf"
189
+ return paper_text
190
+
191
+
192
+ @spaces.GPU(duration=90)
193
+ def generate(paper_text, review_template):
194
+ messages = create_messages(review_template, paper_text)
195
+ input_ids = tokenizer.apply_chat_template(
196
+ messages,
197
+ add_generation_prompt=True,
198
+ return_tensors='pt'
199
+ ).to(model.device)
200
+ print(f"input_ids shape: {input_ids.shape}")
201
+ generation_kwargs = dict(input_ids=input_ids, streamer=streamer, max_new_tokens=4096, do_sample=True, temperature=0.6, top_p=0.9)
202
+ thread = Thread(target=model.generate, kwargs=generation_kwargs)
203
+ thread.start()
204
+ generated_text = ""
205
+ for new_text in streamer:
206
+ generated_text += new_text
207
+ yield generated_text.replace("<|eot_id|>", "")
208
+
209
+
210
+
211
+ # ui
212
+ #8C1B13 red
213
+ #4D8093 blue
214
+ #767676 med grey
215
+ #EFECE3 light grey
216
+ #DDDDDD silver below red
217
+ #FFFDFA white
218
+
219
+ title = """<h1 align="center">OpenReviewer</h1>
220
+ <div align="center">Using <a href="https://huggingface.co/maxidl/Llama-OpenReviewer-8B" target="_blank"><code>Llama-OpenReviewer-8B</code></a> - Built with Llama</div>
221
+ """
222
+
223
+ description = """This is an online demo featuring [Llama-OpenReviewer-8B](https://huggingface.co/maxidl/Llama-OpenReviewer-8B), a large language model that generates high-quality reviews for machine learning and AI papers.
224
+
225
+ ## Demo Guidelines
226
+
227
+ 1. Upload you paper as a pdf file. Alternatively you can paste the full text of your paper in markdown format below. We do **not** store your data. User data is kept in ephemeral storage during processing.
228
+
229
+ 2. Once you upload a pdf it will be converted to markdown. This takes some time as it runs multiple transformer models to parse the layout and extract text and tables. Checkout [marker](https://github.com/VikParuchuri/marker/tree/master) for details.
230
+
231
+ 3. Having obtained a markdown version of your paper, you can now click *Generate Review*.
232
+
233
+ Take a look at the Review Template to properly interpret the generated review. You can also change the review template before generating in case you want to generate a review with a different schema and aspects.
234
+
235
+ To obtain more than one review, just generate again.
236
+
237
+ **GPU quota:** If exceeded, either sign in with your HF account or come back later. Your quota has a half-life of 2 hours.
238
+
239
+ """
240
+
241
+ theme = gr.themes.Default(primary_hue="gray", secondary_hue="blue", neutral_hue="slate")
242
+ with gr.Blocks(theme=theme) as demo:
243
+ title = gr.HTML(title)
244
+ description = gr.Markdown(description)
245
+ file_input = gr.File(file_types=[".pdf"], file_count="single")
246
+ paper_text_field= gr.Textbox("Upload a pdf or paste the full text of your paper in markdown format here.", label="Paper Text", lines=20, max_lines=20, autoscroll=False)
247
+ with gr.Accordion("Review Template", open=False):
248
+ review_template_description = gr.Markdown("We use the ICLR 2025 review template by default, but you can modify the template below as you like.")
249
+ review_template_field = gr.Textbox(label=" ",lines=20, max_lines=20, autoscroll=False, value=REVIEW_FIELDS)
250
+ generate_button = gr.Button("Generate Review", interactive=not paper_text_field)
251
+ file_input.upload(process_file, file_input, paper_text_field)
252
+ paper_text_field.change(lambda text: gr.update(interactive=True) if len(text) > 200 else gr.update(interactive=False), paper_text_field, generate_button)
253
+
254
+ review_field = gr.Markdown("\n\n\n\n\n", label="Review")
255
+ generate_button.click(fn=lambda: gr.update(interactive=False), inputs=None, outputs=generate_button).then(generate, [paper_text_field, review_template_field], review_field).then(fn=lambda: gr.update(interactive=True), inputs=None, outputs=generate_button)
256
+
257
+ demo.title = "OpenReviewer"
258
+
259
+
260
+
261
+
262
+ if __name__ == "__main__":
263
+ demo.launch()