loubnabnl HF staff commited on
Commit
12798fb
1 Parent(s): 29136c5
Files changed (1) hide show
  1. app.py +47 -44
app.py CHANGED
@@ -59,6 +59,7 @@ st.markdown(text)
59
  st.title("2 - Model architecture")
60
  st.markdown("Most code generation models use GPT style architectures trained on code. Some use encoder-decoder architectures such as AlphaCode.")
61
  st.header("Model")
 
62
  with col1:
63
  selected_model = st.selectbox(
64
  "Select a code generation model", MODELS, key=2
@@ -77,51 +78,53 @@ st.markdown(intro)
77
 
78
  # Code generation
79
  st.title("4 - Code generation 💻")
80
- st.header("Models")
81
  with col1:
 
82
  selected_models = st.multiselect(
83
  "Select code generation models to compare", MODELS, default=["CodeParrot"], key=3
84
  )
85
- st.header("Examples")
86
- examples = load_examples()
87
- example_names = [example["name"] for example in examples]
88
- name2id = dict([(name, i) for i, name in enumerate(example_names)])
89
- selected_example = st.selectbox(
90
- "Select one of the following examples or implement yours", example_names
91
- )
92
- example_text = examples[name2id[selected_example]]["value"]
93
- default_length = examples[name2id[selected_example]]["length"]
94
- st.header("Generation settings")
95
- temperature = st.slider(
96
- "Temperature:", value=0.2, min_value=0.0, step=0.1, max_value=2.0
97
- )
98
- max_new_tokens = st.slider(
99
- "Number of tokens to generate:",
100
- value=default_length,
101
- min_value=8,
102
- step=8,
103
- max_value=256,
104
- )
105
- seed = st.slider(
106
- "Random seed:", value=42, min_value=0, step=1, max_value=1000
107
- )
108
- gen_prompt = st.text_area(
109
- "Generate code with prompt:",
110
- value=example_text,
111
- height=220,
112
- ).strip()
113
- if st.button("Generate code!"):
114
- with st.spinner("Generating code..."):
115
- # Create a multiprocessing Pool
116
- pool = Pool()
117
- generate_parallel = partial(
118
- generate_code,
119
- gen_prompt=gen_prompt,
120
- max_new_tokens=max_new_tokens,
121
- temperature=temperature,
122
- seed=seed,
123
- )
124
- output = pool.map(generate_parallel, selected_models)
125
- for i in range(len(output)):
126
- st.markdown(f"**{selected_models[i]}**")
127
- st.code(output[i])
 
 
59
  st.title("2 - Model architecture")
60
  st.markdown("Most code generation models use GPT style architectures trained on code. Some use encoder-decoder architectures such as AlphaCode.")
61
  st.header("Model")
62
+ col1, col2= st.columns([1,2])
63
  with col1:
64
  selected_model = st.selectbox(
65
  "Select a code generation model", MODELS, key=2
 
78
 
79
  # Code generation
80
  st.title("4 - Code generation 💻")
81
+ col1, col2 = st.columns(2)
82
  with col1:
83
+ st.subheader("Models")
84
  selected_models = st.multiselect(
85
  "Select code generation models to compare", MODELS, default=["CodeParrot"], key=3
86
  )
87
+ st.subheader("Examples")
88
+ examples = load_examples()
89
+ example_names = [example["name"] for example in examples]
90
+ name2id = dict([(name, i) for i, name in enumerate(example_names)])
91
+ selected_example = st.selectbox(
92
+ "Select one of the following examples or implement yours", example_names
93
+ )
94
+ example_text = examples[name2id[selected_example]]["value"]
95
+ default_length = examples[name2id[selected_example]]["length"]
96
+ st.subheader("Generation settings")
97
+ temperature = st.slider(
98
+ "Temperature:", value=0.2, min_value=0.0, step=0.1, max_value=2.0
99
+ )
100
+ max_new_tokens = st.slider(
101
+ "Number of tokens to generate:",
102
+ value=default_length,
103
+ min_value=8,
104
+ step=8,
105
+ max_value=256,
106
+ )
107
+ seed = st.slider(
108
+ "Random seed:", value=42, min_value=0, step=1, max_value=1000
109
+ )
110
+ with col2:
111
+ gen_prompt = st.text_area(
112
+ "Generate code with prompt:",
113
+ value=example_text,
114
+ height=220,
115
+ ).strip()
116
+ if st.button("Generate code!"):
117
+ with st.spinner("Generating code..."):
118
+ # Create a multiprocessing Pool
119
+ pool = Pool()
120
+ generate_parallel = partial(
121
+ generate_code,
122
+ gen_prompt=gen_prompt,
123
+ max_new_tokens=max_new_tokens,
124
+ temperature=temperature,
125
+ seed=seed,
126
+ )
127
+ output = pool.map(generate_parallel, selected_models)
128
+ for i in range(len(output)):
129
+ st.markdown(f"**{selected_models[i]}**")
130
+ st.code(output[i])