Spaces:
Running
Running
openreviewer
commited on
Commit
•
a5df6bb
1
Parent(s):
74fe564
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
@@ -30,18 +30,16 @@ use_real_api = False
|
|
30 |
|
31 |
# Function to generate a paper_id using SHA-512 hash
|
32 |
def generate_paper_id(paper_content):
|
33 |
-
if isinstance(paper_content, str):
|
34 |
-
paper_content = paper_content.encode('utf-8')
|
35 |
return hashlib.sha512(paper_content).hexdigest()
|
36 |
|
37 |
# Function to get user IP address
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
def review_papers(pdf_file
|
45 |
logging.info(f"Received file type: {type(pdf_file)}")
|
46 |
paper_content = pdf_file.read() if hasattr(pdf_file, 'read') else pdf_file # Read the content of the uploaded PDF file
|
47 |
if use_real_api:
|
@@ -103,8 +101,8 @@ def review_papers(pdf_file, user_ip):
|
|
103 |
logging.debug(f"Final formatted reviews: {review_texts}")
|
104 |
return review_texts[0], review_texts[1], gr.update(visible=True), gr.update(visible=True), model_a, model_b, paper_content
|
105 |
|
106 |
-
def handle_vote(vote, model_a, model_b, paper_content
|
107 |
-
user_id =
|
108 |
paper_id = generate_paper_id(paper_content) # Generate paper_id from paper content
|
109 |
|
110 |
# Write the request
|
@@ -167,17 +165,6 @@ def setup_interface():
|
|
167 |
}
|
168 |
"""
|
169 |
with gr.Blocks(css=css) as demo:
|
170 |
-
gr.HTML("""
|
171 |
-
<input type="hidden" id="user-ip" value="">
|
172 |
-
<script>
|
173 |
-
async function getUserIP() {
|
174 |
-
const response = await fetch('https://api.ipify.org?format=json');
|
175 |
-
const data = await response.json();
|
176 |
-
document.getElementById('user-ip').value = data.ip;
|
177 |
-
}
|
178 |
-
window.onload = getUserIP;
|
179 |
-
</script>
|
180 |
-
""")
|
181 |
with gr.Tabs():
|
182 |
with gr.TabItem("Reviewer Arena"):
|
183 |
gr.Markdown("## Reviewer Arena")
|
@@ -201,14 +188,14 @@ def setup_interface():
|
|
201 |
|
202 |
model_identity_message = gr.HTML("", visible=False)
|
203 |
|
204 |
-
def handle_vote_interface(vote, model_identity_message_a, model_identity_message_b, paper_content
|
205 |
-
return handle_vote(vote, model_identity_message_a, model_identity_message_b, paper_content
|
206 |
|
207 |
-
submit_button.click(fn=review_papers, inputs=[file_input
|
208 |
-
|
209 |
|
210 |
-
vote_button.click(fn=handle_vote_interface, inputs=[vote, model_identity_message, model_identity_message
|
211 |
-
|
212 |
|
213 |
another_paper_button.click(fn=lambda: None, inputs=None, outputs=None, js="() => { location.reload(); }")
|
214 |
|
@@ -218,7 +205,6 @@ def setup_interface():
|
|
218 |
# Fetch the leaderboard data from the database
|
219 |
leaderboard_data = get_leaderboard()
|
220 |
print(leaderboard_data)
|
221 |
-
|
222 |
|
223 |
# Create the leaderboard HTML dynamically
|
224 |
leaderboard_html = """
|
@@ -264,9 +250,7 @@ def setup_interface():
|
|
264 |
return demo
|
265 |
|
266 |
|
267 |
-
|
268 |
-
|
269 |
if __name__ == "__main__":
|
270 |
logging.basicConfig(level=logging.INFO)
|
271 |
demo = setup_interface()
|
272 |
-
demo.launch()
|
|
|
30 |
|
31 |
# Function to generate a paper_id using SHA-512 hash
|
32 |
def generate_paper_id(paper_content):
|
|
|
|
|
33 |
return hashlib.sha512(paper_content).hexdigest()
|
34 |
|
35 |
# Function to get user IP address
|
36 |
+
def get_user_ip():
|
37 |
+
try:
|
38 |
+
return request.remote_addr
|
39 |
+
except:
|
40 |
+
return "Unknown"
|
41 |
|
42 |
+
def review_papers(pdf_file):
|
43 |
logging.info(f"Received file type: {type(pdf_file)}")
|
44 |
paper_content = pdf_file.read() if hasattr(pdf_file, 'read') else pdf_file # Read the content of the uploaded PDF file
|
45 |
if use_real_api:
|
|
|
101 |
logging.debug(f"Final formatted reviews: {review_texts}")
|
102 |
return review_texts[0], review_texts[1], gr.update(visible=True), gr.update(visible=True), model_a, model_b, paper_content
|
103 |
|
104 |
+
def handle_vote(vote, model_a, model_b, paper_content):
|
105 |
+
user_id = get_user_ip() # Get the user IP address as user_id
|
106 |
paper_id = generate_paper_id(paper_content) # Generate paper_id from paper content
|
107 |
|
108 |
# Write the request
|
|
|
165 |
}
|
166 |
"""
|
167 |
with gr.Blocks(css=css) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
with gr.Tabs():
|
169 |
with gr.TabItem("Reviewer Arena"):
|
170 |
gr.Markdown("## Reviewer Arena")
|
|
|
188 |
|
189 |
model_identity_message = gr.HTML("", visible=False)
|
190 |
|
191 |
+
def handle_vote_interface(vote, model_identity_message_a, model_identity_message_b, paper_content):
|
192 |
+
return handle_vote(vote, model_identity_message_a, model_identity_message_b, paper_content)
|
193 |
|
194 |
+
submit_button.click(fn=review_papers, inputs=[file_input],
|
195 |
+
outputs=[review1, review2, vote, vote_button, model_identity_message, model_identity_message])
|
196 |
|
197 |
+
vote_button.click(fn=handle_vote_interface, inputs=[vote, model_identity_message, model_identity_message],
|
198 |
+
outputs=[vote_message, vote, vote_button, another_paper_button])
|
199 |
|
200 |
another_paper_button.click(fn=lambda: None, inputs=None, outputs=None, js="() => { location.reload(); }")
|
201 |
|
|
|
205 |
# Fetch the leaderboard data from the database
|
206 |
leaderboard_data = get_leaderboard()
|
207 |
print(leaderboard_data)
|
|
|
208 |
|
209 |
# Create the leaderboard HTML dynamically
|
210 |
leaderboard_html = """
|
|
|
250 |
return demo
|
251 |
|
252 |
|
|
|
|
|
253 |
if __name__ == "__main__":
|
254 |
logging.basicConfig(level=logging.INFO)
|
255 |
demo = setup_interface()
|
256 |
+
demo.launch()
|