loubnabnl HF staff commited on
Commit
25f90dd
1 Parent(s): 02a9aa1

reformat code

Browse files
Files changed (1) hide show
  1. app.py +48 -32
app.py CHANGED
@@ -8,6 +8,7 @@ import streamlit as st
8
  MODELS = ["CodeParrot", "InCoder", "CodeGen", "PolyCoder"]
9
  GENERATION_MODELS = ["CodeParrot", "InCoder", "CodeGen"]
10
 
 
11
  @st.cache()
12
  def load_examples():
13
  with open("utils/examples.json", "r") as f:
@@ -18,10 +19,12 @@ def load_examples():
18
  def read_markdown(path):
19
  with open(path, "r") as f:
20
  output = f.read()
21
- st.markdown(output, unsafe_allow_html=True)
22
-
23
-
24
- def generate_code(generations, model_name, gen_prompt, max_new_tokens, temperature, seed):
 
 
25
  # call space using its API endpoint
26
  url = (
27
  f"https://hf.space/embed/loubnabnl/{model_name.lower()}-subspace/+/api/predict/"
@@ -30,21 +33,33 @@ def generate_code(generations, model_name, gen_prompt, max_new_tokens, temperatu
30
  url=url, json={"data": [gen_prompt, max_new_tokens, temperature, seed]}
31
  )
32
  generated_text = r.json()["data"][0]
33
- generations.append(generated_text)
34
-
35
-
36
- def generate_code_threads(generations, models, gen_prompt, max_new_tokens, temperature, seed):
37
- threads = []
38
- for model_name in models:
39
- # create the thread
40
- threads.append(
41
- threading.Thread(target=generate_code, args=(generations, model_name, gen_prompt, max_new_tokens, temperature, seed))
42
- )
43
- threads[-1].start()
44
-
45
- for t in threads:
46
- t.join()
47
-
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  st.set_page_config(page_icon=":laptop:", layout="wide")
50
  with open("utils/table_contents.txt", "r") as f:
@@ -59,12 +74,12 @@ read_markdown("utils/intro.txt")
59
  st.subheader("1 - Code datasets")
60
  read_markdown("datasets/intro.txt")
61
  read_markdown("datasets/github_code.txt")
62
- #GITHUB_CODE = "https://huggingface.co/datasets/lvwerra/github-code"
63
- #st.markdown(f"Preview of some code files from Github repositories in [Github-code dataset]({GITHUB_CODE}):")
64
- #df = pd.read_csv("utils/data_preview.csv")
65
- #st.dataframe(df)
66
 
67
- col1, col2= st.columns([1,2])
68
  with col1:
69
  selected_model = st.selectbox("", MODELS, key=1)
70
  read_markdown(f"datasets/{selected_model.lower()}.txt")
@@ -73,7 +88,7 @@ read_markdown(f"datasets/{selected_model.lower()}.txt")
73
  # Model architecture
74
  st.subheader("2 - Model architecture")
75
  read_markdown("architectures/intro.txt")
76
- col1, col2= st.columns([1,2])
77
  with col1:
78
  selected_model = st.selectbox("", MODELS, key=2)
79
  read_markdown(f"architectures/{selected_model.lower()}.txt")
@@ -85,12 +100,15 @@ read_markdown("evaluation/demo_humaneval.txt")
85
 
86
  # Code generation
87
  st.subheader("4 - Code generation ✨")
88
- col1, col2, col3 = st.columns([7,1,6])
89
  with col1:
90
  st.markdown("**Models**")
91
  selected_models = st.multiselect(
92
- "Select code generation models to compare:", GENERATION_MODELS, default=["CodeParrot"], key=3
93
- )
 
 
 
94
  st.markdown(" ")
95
  st.markdown("**Examples**")
96
  examples = load_examples()
@@ -113,9 +131,7 @@ with col3:
113
  step=4,
114
  max_value=256,
115
  )
116
- seed = st.slider(
117
- "Random seed:", value=42, min_value=0, step=1, max_value=1000
118
- )
119
  gen_prompt = st.text_area(
120
  "Generate code with prompt:",
121
  value=example_text,
@@ -141,4 +157,4 @@ if st.button("Generate code!"):
141
 
142
  # Resources
143
  st.subheader("Resources")
144
- read_markdown("utils/resources.txt")
 
8
  MODELS = ["CodeParrot", "InCoder", "CodeGen", "PolyCoder"]
9
  GENERATION_MODELS = ["CodeParrot", "InCoder", "CodeGen"]
10
 
11
+
12
  @st.cache()
13
  def load_examples():
14
  with open("utils/examples.json", "r") as f:
 
19
  def read_markdown(path):
20
  with open(path, "r") as f:
21
  output = f.read()
22
+ st.markdown(output, unsafe_allow_html=True)
23
+
24
+
25
+ def generate_code(
26
+ generations, model_name, gen_prompt, max_new_tokens, temperature, seed
27
+ ):
28
  # call space using its API endpoint
29
  url = (
30
  f"https://hf.space/embed/loubnabnl/{model_name.lower()}-subspace/+/api/predict/"
 
33
  url=url, json={"data": [gen_prompt, max_new_tokens, temperature, seed]}
34
  )
35
  generated_text = r.json()["data"][0]
36
+ generations.append(generated_text)
37
+
38
+
39
+ def generate_code_threads(
40
+ generations, models, gen_prompt, max_new_tokens, temperature, seed
41
+ ):
42
+ threads = []
43
+ for model_name in models:
44
+ # create the thread
45
+ threads.append(
46
+ threading.Thread(
47
+ target=generate_code,
48
+ args=(
49
+ generations,
50
+ model_name,
51
+ gen_prompt,
52
+ max_new_tokens,
53
+ temperature,
54
+ seed,
55
+ ),
56
+ )
57
+ )
58
+ threads[-1].start()
59
+
60
+ for t in threads:
61
+ t.join()
62
+
63
 
64
  st.set_page_config(page_icon=":laptop:", layout="wide")
65
  with open("utils/table_contents.txt", "r") as f:
 
74
  st.subheader("1 - Code datasets")
75
  read_markdown("datasets/intro.txt")
76
  read_markdown("datasets/github_code.txt")
77
+ # GITHUB_CODE = "https://huggingface.co/datasets/lvwerra/github-code"
78
+ # st.markdown(f"Preview of some code files from Github repositories in [Github-code dataset]({GITHUB_CODE}):")
79
+ # df = pd.read_csv("utils/data_preview.csv")
80
+ # st.dataframe(df)
81
 
82
+ col1, col2 = st.columns([1, 2])
83
  with col1:
84
  selected_model = st.selectbox("", MODELS, key=1)
85
  read_markdown(f"datasets/{selected_model.lower()}.txt")
 
88
  # Model architecture
89
  st.subheader("2 - Model architecture")
90
  read_markdown("architectures/intro.txt")
91
+ col1, col2 = st.columns([1, 2])
92
  with col1:
93
  selected_model = st.selectbox("", MODELS, key=2)
94
  read_markdown(f"architectures/{selected_model.lower()}.txt")
 
100
 
101
  # Code generation
102
  st.subheader("4 - Code generation ✨")
103
+ col1, col2, col3 = st.columns([7, 1, 6])
104
  with col1:
105
  st.markdown("**Models**")
106
  selected_models = st.multiselect(
107
+ "Select code generation models to compare:",
108
+ GENERATION_MODELS,
109
+ default=["CodeParrot"],
110
+ key=3,
111
+ )
112
  st.markdown(" ")
113
  st.markdown("**Examples**")
114
  examples = load_examples()
 
131
  step=4,
132
  max_value=256,
133
  )
134
+ seed = st.slider("Random seed:", value=42, min_value=0, step=1, max_value=1000)
 
 
135
  gen_prompt = st.text_area(
136
  "Generate code with prompt:",
137
  value=example_text,
 
157
 
158
  # Resources
159
  st.subheader("Resources")
160
+ read_markdown("utils/resources.txt")