Last active
November 19, 2020 07:57
-
-
Save faizankshaikh/3ef6d636da0fcffb81b4486df3991ca3 to your computer and use it in GitHub Desktop.
typing_tutor_article_code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TypingTutor: | |
def __init__(self): | |
st.set_page_config(page_title="Typing Tutor", layout="wide") | |
st.markdown( | |
"<h1 style='text-align: center; color: black;'>Typing Tutor</h1>", | |
unsafe_allow_html=True, | |
) | |
self.col1, self.col2 = st.beta_columns(2) | |
placeholder = st.empty() | |
with self.col1: | |
self.start_button = st.button("Start!", key="start_button") | |
st.subheader("Text to write") | |
with placeholder.beta_container(): | |
st.subheader("Steps to check your Typing speed") | |
st.write( | |
"1. When you are ready, click on the start button which will generate code for you to write on the left hand side. A point to note that the timer starts as soon as you click on the start button" | |
) | |
st.write( | |
"2. Start writing the same code on the code window given on the right hand side. When you're done - press 'CTRL + ENTER' to save your code. **Remember to do this as this ensures that the code you have written is ready for submission**" | |
) | |
st.write( | |
"3. Lastly, click on Check Speed button to check you writing accuracy and the writing speed. Good luck!" | |
) | |
with self.col2: | |
self.eval_button = st.button("Check Speed", key="eval_button") | |
st.subheader("Text Input") | |
st.write("") | |
self.session_state.content = st_ace( | |
placeholder="Start typing here ...", | |
language="python", | |
theme="solarized_light", | |
keybinding="sublime", | |
font_size=20, | |
tab_size=4, | |
show_gutter=True, | |
show_print_margin=True, | |
wrap=True, | |
readonly=False, | |
auto_update=False, | |
key="ace-editor", | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _code_gen(self, context, realtime=True): | |
if realtime: | |
input_ids = self.tokenizer.encode( | |
"<python> " + context, return_tensors="pt" | |
) | |
outputs = self.model.generate( | |
input_ids=input_ids, | |
max_length=256, | |
temperature=0.7, | |
num_return_sequences=1, | |
) | |
text = self.tokenizer.decode(outputs[0], skip_special_tokens=True) | |
return text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment