Spaces:
Sleeping
Sleeping
Elfsong
commited on
Commit
·
36e34dd
1
Parent(s):
35d97a6
submit
Browse files
app.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Venus Annotation System
|
| 2 |
+
# Author: Du Mingzhe (mingzhe@nus.edu.sg)
|
| 3 |
+
# Date: 2024-09-25
|
| 4 |
+
|
| 5 |
+
import uuid
|
| 6 |
+
import streamlit as st
|
| 7 |
+
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 |
+
|
| 14 |
+
# Step 1: Load the problem set
|
| 15 |
+
my_bar = st.progress(0, text="Loading the problem set...")
|
| 16 |
+
|
| 17 |
+
my_bar.progress(10, text="Loading [Elfsong/Venus] datasets...")
|
| 18 |
+
if "raw_ds" not in st.session_state.keys():
|
| 19 |
+
st.session_state["raw_ds"] = load_dataset("Elfsong/Venus", "python3")
|
| 20 |
+
raw_ds = st.session_state["raw_ds"]
|
| 21 |
+
|
| 22 |
+
my_bar.progress(55, text="Loading [Elfsong/venus_case] datasets...")
|
| 23 |
+
if "case_ds" not in st.session_state.keys():
|
| 24 |
+
st.session_state["case_ds"] = load_dataset("Elfsong/venus_case", "python3")
|
| 25 |
+
case_ds = st.session_state["case_ds"]
|
| 26 |
+
|
| 27 |
+
my_bar.progress(90, text="Filtering out the cases that already exist...")
|
| 28 |
+
if "candidates" not in st.session_state.keys():
|
| 29 |
+
case_ds_ids = set(case_ds['train']['question_id'])
|
| 30 |
+
candidates = [raw_ds['train'][i] for i in range(len(raw_ds['train'])) if raw_ds['train'][i]['question_id'] not in case_ds_ids]
|
| 31 |
+
st.session_state["candidates"] = candidates
|
| 32 |
+
candidates = st.session_state["candidates"]
|
| 33 |
+
|
| 34 |
+
my_bar.progress(100, text="System Initialized Successfully 🚀")
|
| 35 |
+
|
| 36 |
+
# Step 2: Select the problem
|
| 37 |
+
candidates_dict = {}
|
| 38 |
+
for candidate in candidates:
|
| 39 |
+
candidate_name = str(candidate['question_id']) + '.' + str(candidate['name']) + ' [' + str(candidate['difficulty']).upper() + ']'
|
| 40 |
+
candidates_dict[candidate_name] = candidate
|
| 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",
|
| 61 |
+
"primary": True,
|
| 62 |
+
"hasText": True,
|
| 63 |
+
"showWithIcon": True,
|
| 64 |
+
"commands": ["submit"],
|
| 65 |
+
"style": {"bottom": "0.44rem","right": "0.4rem"}
|
| 66 |
+
}]
|
| 67 |
+
predefined_code = "def generate_test_cases():\n\tpass\n\ndef serialize_input():\n\tpass\n\ndef deserialize_input():\n\tpass\n\ndef serialize_output():\n\tpass\n\ndef deserialize_output():\n\tpass"
|
| 68 |
+
response_dict = code_editor(predefined_code, lang="python", height=20, options={"wrap": False}, buttons=editor_buttons)
|
| 69 |
+
if response_dict['type'] == 'submit':
|
| 70 |
+
new_ds = Dataset.from_list([{
|
| 71 |
+
"question_id": example['question_id'],
|
| 72 |
+
"test_case_functions": response_dict['text'],
|
| 73 |
+
}])
|
| 74 |
+
|
| 75 |
+
ds_name = str(uuid.uuid1())
|
| 76 |
+
new_ds.push_to_hub(f"Elfsong/Venus_Anotation", f'python3-{ds_name}')
|
| 77 |
+
st.write("Thanks for your contribution! 🌟")
|
| 78 |
+
|