Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,8 +10,10 @@ from text_generation import Client
|
|
| 10 |
from share_btn import community_icon_html, loading_icon_html, share_js, share_btn_css
|
| 11 |
|
| 12 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
|
|
|
| 13 |
API_URL = "https://api-inference.huggingface.co/models/bigcode/starcoder"
|
| 14 |
API_URL_BASE ="https://api-inference.huggingface.co/models/bigcode/starcoderbase"
|
|
|
|
| 15 |
|
| 16 |
FIM_PREFIX = "<fim_prefix>"
|
| 17 |
FIM_MIDDLE = "<fim_middle>"
|
|
@@ -80,6 +82,9 @@ client = Client(
|
|
| 80 |
client_base = Client(
|
| 81 |
API_URL_BASE, headers={"Authorization": f"Bearer {HF_TOKEN}"},
|
| 82 |
)
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
def generate(
|
| 85 |
prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0, version="StarCoder",
|
|
@@ -110,6 +115,8 @@ def generate(
|
|
| 110 |
|
| 111 |
if version == "StarCoder":
|
| 112 |
stream = client.generate_stream(prompt, **generate_kwargs)
|
|
|
|
|
|
|
| 113 |
else:
|
| 114 |
stream = client_base.generate_stream(prompt, **generate_kwargs)
|
| 115 |
|
|
@@ -135,6 +142,7 @@ def generate(
|
|
| 135 |
examples = [
|
| 136 |
"X_train, y_train, X_test, y_test = train_test_split(X, y, test_size=0.1)\n\n# Train a logistic regression model, predict the labels on the test set and compute the accuracy score",
|
| 137 |
"// Returns every other value in the array as a new array.\nfunction everyOther(arr) {",
|
|
|
|
| 138 |
"def alternating(list1, list2):\n results = []\n for i in range(min(len(list1), len(list2))):\n results.append(list1[i])\n results.append(list2[i])\n if len(list1) > len(list2):\n <FILL_HERE>\n else:\n results.extend(list2[i+1:])\n return results",
|
| 139 |
]
|
| 140 |
|
|
@@ -159,9 +167,16 @@ css += share_btn_css + monospace_css + ".gradio-container {color: black}"
|
|
| 159 |
|
| 160 |
description = """
|
| 161 |
<div style="text-align: center;">
|
| 162 |
-
<h1>
|
| 163 |
-
<p>This is a demo to generate code with
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
</div>
|
| 166 |
"""
|
| 167 |
disclaimer = """⚠️<b>Any use or sharing of this demo constitues your acceptance of the BigCode [OpenRAIL-M](https://huggingface.co/spaces/bigcode/bigcode-model-license-agreement) License Agreement and the use restrictions included within.</b>\
|
|
@@ -170,15 +185,23 @@ disclaimer = """⚠️<b>Any use or sharing of this demo constitues your accepta
|
|
| 170 |
with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
| 171 |
with gr.Column():
|
| 172 |
gr.Markdown(description)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
with gr.Row():
|
| 174 |
with gr.Column():
|
| 175 |
instruction = gr.Textbox(
|
| 176 |
placeholder="Enter your code here",
|
| 177 |
-
|
|
|
|
| 178 |
elem_id="q-input",
|
| 179 |
)
|
| 180 |
submit = gr.Button("Generate", variant="primary")
|
| 181 |
-
output = gr.Code(elem_id="q-output", lines=30)
|
| 182 |
with gr.Row():
|
| 183 |
with gr.Column():
|
| 184 |
with gr.Accordion("Advanced settings", open=False):
|
|
@@ -222,13 +245,7 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
|
| 222 |
interactive=True,
|
| 223 |
info="Penalize repeated tokens",
|
| 224 |
)
|
| 225 |
-
|
| 226 |
-
version = gr.Dropdown(
|
| 227 |
-
["StarCoderBase", "StarCoder"],
|
| 228 |
-
value="StarCoder",
|
| 229 |
-
label="Version",
|
| 230 |
-
info="",
|
| 231 |
-
)
|
| 232 |
gr.Markdown(disclaimer)
|
| 233 |
with gr.Group(elem_id="share-btn-container"):
|
| 234 |
community_icon = gr.HTML(community_icon_html, visible=True)
|
|
|
|
| 10 |
from share_btn import community_icon_html, loading_icon_html, share_js, share_btn_css
|
| 11 |
|
| 12 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 13 |
+
|
| 14 |
API_URL = "https://api-inference.huggingface.co/models/bigcode/starcoder"
|
| 15 |
API_URL_BASE ="https://api-inference.huggingface.co/models/bigcode/starcoderbase"
|
| 16 |
+
API_URL_PLUS = "https://api-inference.huggingface.co/models/bigcode/starcoderplus"
|
| 17 |
|
| 18 |
FIM_PREFIX = "<fim_prefix>"
|
| 19 |
FIM_MIDDLE = "<fim_middle>"
|
|
|
|
| 82 |
client_base = Client(
|
| 83 |
API_URL_BASE, headers={"Authorization": f"Bearer {HF_TOKEN}"},
|
| 84 |
)
|
| 85 |
+
client_plus = Client(
|
| 86 |
+
API_URL_PLUS, headers={"Authorization": f"Bearer {HF_TOKEN}"},
|
| 87 |
+
)
|
| 88 |
|
| 89 |
def generate(
|
| 90 |
prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0, version="StarCoder",
|
|
|
|
| 115 |
|
| 116 |
if version == "StarCoder":
|
| 117 |
stream = client.generate_stream(prompt, **generate_kwargs)
|
| 118 |
+
elif version == "StarCoderPlus":
|
| 119 |
+
stream = client_plus.generate_stream(prompt, **generate_kwargs)
|
| 120 |
else:
|
| 121 |
stream = client_base.generate_stream(prompt, **generate_kwargs)
|
| 122 |
|
|
|
|
| 142 |
examples = [
|
| 143 |
"X_train, y_train, X_test, y_test = train_test_split(X, y, test_size=0.1)\n\n# Train a logistic regression model, predict the labels on the test set and compute the accuracy score",
|
| 144 |
"// Returns every other value in the array as a new array.\nfunction everyOther(arr) {",
|
| 145 |
+
"Poor English: She no went to the market. Corrected English:",
|
| 146 |
"def alternating(list1, list2):\n results = []\n for i in range(min(len(list1), len(list2))):\n results.append(list1[i])\n results.append(list2[i])\n if len(list1) > len(list2):\n <FILL_HERE>\n else:\n results.extend(list2[i+1:])\n return results",
|
| 147 |
]
|
| 148 |
|
|
|
|
| 167 |
|
| 168 |
description = """
|
| 169 |
<div style="text-align: center;">
|
| 170 |
+
<h1> ⭐ StarCoder <span style='color: #e6b800;'>Models</span> Playground</h1>
|
| 171 |
+
<p>This is a demo to generate text and code with the following StarCoder models:</p>
|
| 172 |
+
</div>
|
| 173 |
+
<div style="text-align: left;">
|
| 174 |
+
<ul>
|
| 175 |
+
<li><a href="https://huggingface.co/bigcode/starcoderplus" style='color: #e6b800;'>StarCoderPlus</a>: A finetuned version of StarCoderBase on English web data, making it strong in both English text and code generation.</li>
|
| 176 |
+
<li><a href="https://huggingface.co/bigcode/starcoderbase" style='color: #e6b800;'>StarCoderBase</a>: A code generation model trained on 80+ programming languages, providing broad language coverage for code generation tasks.</li>
|
| 177 |
+
<li><a href="https://huggingface.co/bigcode/starcoder" style='color: #e6b800;'>StarCoder</a>: A finetuned version of StarCoderBase specifically focused on Python, while also maintaining strong performance on other programming languages.</li>
|
| 178 |
+
</ul>
|
| 179 |
+
<p><b>Please note:</b> These models are not designed for instruction purposes. If you're looking for instruction or want to chat with a fine-tuned model, you can visit the <a href="https://huggingface.co/spaces/HuggingFaceH4/starchat-playground">StarChat Playground</a>.</p>
|
| 180 |
</div>
|
| 181 |
"""
|
| 182 |
disclaimer = """⚠️<b>Any use or sharing of this demo constitues your acceptance of the BigCode [OpenRAIL-M](https://huggingface.co/spaces/bigcode/bigcode-model-license-agreement) License Agreement and the use restrictions included within.</b>\
|
|
|
|
| 185 |
with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
| 186 |
with gr.Column():
|
| 187 |
gr.Markdown(description)
|
| 188 |
+
with gr.Row():
|
| 189 |
+
version = gr.Dropdown(
|
| 190 |
+
["StarCoderPlus", "StarCoderBase", "StarCoder"],
|
| 191 |
+
value="StarCoderPlus",
|
| 192 |
+
label="Model",
|
| 193 |
+
info="Choose a model from the list",
|
| 194 |
+
)
|
| 195 |
with gr.Row():
|
| 196 |
with gr.Column():
|
| 197 |
instruction = gr.Textbox(
|
| 198 |
placeholder="Enter your code here",
|
| 199 |
+
lines=5,
|
| 200 |
+
label="Input",
|
| 201 |
elem_id="q-input",
|
| 202 |
)
|
| 203 |
submit = gr.Button("Generate", variant="primary")
|
| 204 |
+
output = gr.Code(elem_id="q-output", lines=30, label="Output")
|
| 205 |
with gr.Row():
|
| 206 |
with gr.Column():
|
| 207 |
with gr.Accordion("Advanced settings", open=False):
|
|
|
|
| 245 |
interactive=True,
|
| 246 |
info="Penalize repeated tokens",
|
| 247 |
)
|
| 248 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
gr.Markdown(disclaimer)
|
| 250 |
with gr.Group(elem_id="share-btn-container"):
|
| 251 |
community_icon = gr.HTML(community_icon_html, visible=True)
|