kz209 commited on
Commit
c5cb52f
β€’
1 Parent(s): d7f5c38
{pages β†’ html}/leaderboard_template.html RENAMED
File without changes
html/prompt_display.html ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Prompt Details</title>
7
+ </head>
8
+ <body>
9
+ <h1>Prompt Details</h1>
10
+ <div id="prompt-container"></div>
11
+
12
+ <script>
13
+ const urlParams = new URLSearchParams(window.location.search);
14
+ const promptId = urlParams.get('id');
15
+
16
+ // Fetch the prompt data dynamically (you can modify this part based on how you are storing prompts)
17
+ fetch('/prompt/prompt.json') // Assuming prompts are stored in this file
18
+ .then(response => response.json())
19
+ .then(prompts => {
20
+ const prompt = prompts.find(p => p.id === promptId);
21
+ if (prompt) {
22
+ document.getElementById('prompt-container').innerHTML = `
23
+ <h2>Prompt ID: ${promptId}</h2>
24
+ <p><strong>Prompt:</strong> ${prompt.prompt.replace(/\n/g, '<br>')}</p>
25
+ `;
26
+ } else {
27
+ document.getElementById('prompt-container').innerText = "Prompt not found.";
28
+ }
29
+ });
30
+ </script>
31
+ </body>
32
+ </html>
pages/leaderboard.py CHANGED
@@ -3,9 +3,35 @@ import html
3
  import json
4
  import gradio as gr
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  def create_html_with_tooltip(id, prompt):
 
7
  escaped_prompt = html.escape(prompt.replace("\n", "<br />"))
8
- return f'<span class="tooltip" data-id="{id}" data-prompt="{escaped_prompt}">{id}</span>'
9
 
10
  with open("prompt/prompt.json", "r") as file:
11
  json_data = file.read()
@@ -30,10 +56,6 @@ medals = ['πŸ…', 'πŸ₯ˆ', 'πŸ₯‰']
30
  for i in range(3):
31
  df.loc[i, 'Authors'] = f"{medals[i]} {df.loc[i, 'Authors']}"
32
 
33
- def create_html_with_tooltip(id, prompt):
34
- escaped_prompt = html.escape(prompt.replace("\n", "<br />"))
35
- return f'<span class="tooltip" data-id="{id}" data-prompt="{escaped_prompt}">{id}</span>'
36
-
37
  def update_leaderboard(sort_by):
38
  sorted_df = df.sort_values(by=sort_by, ascending=False, ignore_index=True)
39
  sorted_df['Rank'] = range(1, len(sorted_df) + 1)
@@ -47,11 +69,11 @@ def update_leaderboard(sort_by):
47
  f'<th><a href="#" onclick="sortBy(\'{column}\'); return false;">{column}</a></th>')
48
 
49
  # Load the HTML template
50
- with open('pages/leaderboard_template.html', 'r') as file:
51
  template = file.read()
52
 
53
  # Create the sortBy function in JavaScript
54
- sort_by_function = f"""
55
  function sortBy(column) {{
56
  const gradioEl = document.querySelector('gradio-app');
57
  const dropdown = gradioEl.querySelector('select');
 
3
  import json
4
  import gradio as gr
5
 
6
+ import os
7
+
8
+ file_path = "html/prompt_display.html"
9
+
10
+ if os.access(file_path, os.R_OK):
11
+ print(f"{file_path} is readable")
12
+ else:
13
+ print(f"{file_path}is not readable")
14
+
15
+
16
+ file_path = "html/leaderboard_template.html"
17
+
18
+ if os.access(file_path, os.R_OK):
19
+ print(f"{file_path} is readable")
20
+ else:
21
+ print(f"{file_path}is not readable")
22
+
23
+ file_path = "prompt/prompt.json"
24
+
25
+ if os.access(file_path, os.R_OK):
26
+ print(f"{file_path} is readable")
27
+ else:
28
+ print(f"{file_path}is not readable")
29
+
30
+
31
  def create_html_with_tooltip(id, prompt):
32
+ # Create a URL that points to the new page with the prompt ID in the query string
33
  escaped_prompt = html.escape(prompt.replace("\n", "<br />"))
34
+ return f'<a href="html/prompt_display.html?id={id}" class="tooltip" data-id="{id}" data-prompt="{escaped_prompt}">{id}</a>'
35
 
36
  with open("prompt/prompt.json", "r") as file:
37
  json_data = file.read()
 
56
  for i in range(3):
57
  df.loc[i, 'Authors'] = f"{medals[i]} {df.loc[i, 'Authors']}"
58
 
 
 
 
 
59
  def update_leaderboard(sort_by):
60
  sorted_df = df.sort_values(by=sort_by, ascending=False, ignore_index=True)
61
  sorted_df['Rank'] = range(1, len(sorted_df) + 1)
 
69
  f'<th><a href="#" onclick="sortBy(\'{column}\'); return false;">{column}</a></th>')
70
 
71
  # Load the HTML template
72
+ with open('html/leaderboard_template.html', 'r') as file:
73
  template = file.read()
74
 
75
  # Create the sortBy function in JavaScript
76
+ sort_by_function = """
77
  function sortBy(column) {{
78
  const gradioEl = document.querySelector('gradio-app');
79
  const dropdown = gradioEl.querySelector('select');