Spaces:
Sleeping
Sleeping
Elfsong
commited on
Commit
·
195e9fe
1
Parent(s):
7bdce7c
Update
Browse files
app.py
CHANGED
@@ -8,6 +8,49 @@ import streamlit_ext as ste
|
|
8 |
from code_editor import code_editor
|
9 |
from datasets import load_dataset, Dataset
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
st.title(":blue[Venus] Annotation System 🪐")
|
13 |
|
@@ -41,20 +84,26 @@ for candidate in candidates:
|
|
41 |
option = ste.selectbox("Select a problem here", candidates_dict.keys())
|
42 |
example = candidates_dict[option]
|
43 |
|
44 |
-
tab1, tab2, tab3 = st.tabs(["Problem Description", "Canonical Solution", "Test Cases Generator"])
|
45 |
|
46 |
with tab1:
|
47 |
st.html(example['content'])
|
48 |
with tab2:
|
49 |
solutions_displayed = 0
|
|
|
50 |
for solution in example['rt_list']:
|
51 |
if "Solution" in solution['code']:
|
52 |
st.write(f"Canonical Solution {solutions_displayed + 1}")
|
53 |
st.code(solution['code'])
|
|
|
54 |
solutions_displayed += 1
|
55 |
if solutions_displayed >= 3:
|
56 |
break
|
57 |
with tab3:
|
|
|
|
|
|
|
|
|
58 |
editor_buttons = [{
|
59 |
"name": "Submit",
|
60 |
"feather": "Play",
|
|
|
8 |
from code_editor import code_editor
|
9 |
from datasets import load_dataset, Dataset
|
10 |
|
11 |
+
case_generation = """
|
12 |
+
Given the problem description and the canonical solution, write these functions and return in the given JSON format. Import all neccessary libraries in the code.
|
13 |
+
|
14 |
+
Problem Description:
|
15 |
+
{problem_description}
|
16 |
+
|
17 |
+
Canonical Solution:
|
18 |
+
{canonical_solution}
|
19 |
+
|
20 |
+
{{
|
21 |
+
"generate_test_case_input": "a {lang} function 'generate_test_case_input() → Turple' that randomly generate a test case input Turple from a reasonable test range. Wrap the test case input in a tuple.",
|
22 |
+
"serialize_input": "a {lang} function 'serialize_input(Turple) → Str' that takes the test case input {lang} Turple, and generates the serialized test case input string.",
|
23 |
+
"deserialize_input": "a {lang} function 'deserialize_input(Str) → Turple' that takes the serialized test case input string, and generate the {lang} test case input Turple.",
|
24 |
+
"serialize_output": "a {lang} function 'serialize_output(Turple) → Str' that takes the test case output {lang} Turple, and generates the serialized test case output string.",
|
25 |
+
"deserialize_output": "a {lang} function 'deserialize_output(Str) → Turple' that takes the serialized test case output string, and generate the {lang} test case output Turple.",
|
26 |
+
"entry_point": "the entry point function name of the canonical solution"
|
27 |
+
}}
|
28 |
+
|
29 |
+
Example 1:
|
30 |
+
Problem Description:
|
31 |
+
<p>Given an array of integers <code>nums</code> and an integer <code>target</code>, return <em>indices of the two numbers such that they add up to <code>target</code></em>.</p> <p>You may assume that each input would have <strong><em>exactly</em> one solution</strong>, and you may not use the <em>same</em> element twice.</p> <p>You can return the answer in any order.</p> <p> </p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [2,7,11,15], target = 9 <strong>Output:</strong> [0,1] <strong>Explanation:</strong> Because nums[0] + nums[1] == 9, we return [0, 1]. </pre> <p><strong class="example">Example 2:</strong></p> <pre> <strong>Input:</strong> nums = [3,2,4], target = 6 <strong>Output:</strong> [1,2] </pre> <p><strong class="example">Example 3:</strong></p> <pre> <strong>Input:</strong> nums = [3,3], target = 6 <strong>Output:</strong> [0,1] </pre> <p> </p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= nums.length <= 10<sup>4</sup></code></li> <li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li> <li><code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code></li> <li><strong>Only one valid answer exists.</strong></li> </ul> <p> </p> <strong>Follow-up: </strong>Can you come up with an algorithm that is less than <code>O(n<sup>2</sup>)</code><font face="monospace"> </font>time complexity?
|
32 |
+
|
33 |
+
Canonical Solution:
|
34 |
+
class Solution:
|
35 |
+
def twoSum(self, nums: List[int], target: int) -> List[int]:
|
36 |
+
num_map = {{}}
|
37 |
+
for i, num in enumerate(nums):
|
38 |
+
complement = target - num
|
39 |
+
if complement in num_map:
|
40 |
+
return [num_map[complement], i]
|
41 |
+
num_map[num] = i
|
42 |
+
|
43 |
+
Response:
|
44 |
+
{{
|
45 |
+
"generate_test_case_input": "import random\nfrom typing import List, Tuple\n\ndef generate_test_case_input() -> Tuple[List[int], int]:\n length = random.randint(2, 10000)\n nums = [random.randint(-10**9, 10**9) for _ in range(length)]\n idx1, idx2 = random.sample(range(length), 2)\n target = nums[idx1] + nums[idx2]\n return nums, target",
|
46 |
+
"serialize_input": "from typing import List, Tuple\n\ndef serialize_input(input: Tuple[List[int], int]) -> str:\n nums, target = input\n return f'{{nums}}\\n{{target}}'\n",
|
47 |
+
"deserialize_input": "from typing import List, Tuple\n\ndef deserialize_input(serialized: str) -> Tuple[List[int], int]:\n parts = serialized.strip().split('\\n')\n nums = eval(parts[0])\n target = int(parts[1])\n return nums, target\n",
|
48 |
+
"serialize_output": "from typing import List\n\ndef serialize_output(output: List[int]) -> str:\n return str(output)\n",
|
49 |
+
"deserialize_output": "from typing import List\n\ndef deserialize_output(serialized: str) -> List[int]:\n return eval(serialized)\n",
|
50 |
+
"entry_point": "twoSum"
|
51 |
+
}}
|
52 |
+
"""
|
53 |
+
|
54 |
|
55 |
st.title(":blue[Venus] Annotation System 🪐")
|
56 |
|
|
|
84 |
option = ste.selectbox("Select a problem here", candidates_dict.keys())
|
85 |
example = candidates_dict[option]
|
86 |
|
87 |
+
tab1, tab2, tab3, tab4 = st.tabs(["Problem Description", "Canonical Solution", "Test Cases Generator"])
|
88 |
|
89 |
with tab1:
|
90 |
st.html(example['content'])
|
91 |
with tab2:
|
92 |
solutions_displayed = 0
|
93 |
+
canonical_solutions = list()
|
94 |
for solution in example['rt_list']:
|
95 |
if "Solution" in solution['code']:
|
96 |
st.write(f"Canonical Solution {solutions_displayed + 1}")
|
97 |
st.code(solution['code'])
|
98 |
+
canonical_solutions.append(solution['code'])
|
99 |
solutions_displayed += 1
|
100 |
if solutions_displayed >= 3:
|
101 |
break
|
102 |
with tab3:
|
103 |
+
prompt = case_generation.format(problem_description=example['content'], canonical_solution=canonical_solutions[0], lang="python3")
|
104 |
+
st.write(prompt)
|
105 |
+
|
106 |
+
with tab4:
|
107 |
editor_buttons = [{
|
108 |
"name": "Submit",
|
109 |
"feather": "Play",
|