Update app.py
Browse files
app.py
CHANGED
|
@@ -11,9 +11,7 @@ from share_btn import community_icon_html, loading_icon_html, share_js, share_bt
|
|
| 11 |
|
| 12 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 13 |
|
| 14 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
| 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>"
|
|
@@ -21,46 +19,6 @@ FIM_SUFFIX = "<fim_suffix>"
|
|
| 21 |
|
| 22 |
FIM_INDICATOR = "<FILL_HERE>"
|
| 23 |
|
| 24 |
-
FORMATS = """## Model Formats
|
| 25 |
-
|
| 26 |
-
The model is pretrained on code and is formatted with special tokens in addition to the pure code data,\
|
| 27 |
-
such as prefixes specifying the source of the file or tokens separating code from a commit message.\
|
| 28 |
-
Use these templates to explore the model's capacities:
|
| 29 |
-
|
| 30 |
-
### 1. Prefixes 🏷️
|
| 31 |
-
For pure code files, use any combination of the following prefixes:
|
| 32 |
-
|
| 33 |
-
```
|
| 34 |
-
<reponame>REPONAME<filename>FILENAME<gh_stars>STARS\ncode<|endoftext|>
|
| 35 |
-
```
|
| 36 |
-
STARS can be one of: 0, 1-10, 10-100, 100-1000, 1000+
|
| 37 |
-
|
| 38 |
-
### 2. Commits 💾
|
| 39 |
-
The commits data is formatted as follows:
|
| 40 |
-
|
| 41 |
-
```
|
| 42 |
-
<commit_before>code<commit_msg>text<commit_after>code<|endoftext|>
|
| 43 |
-
```
|
| 44 |
-
|
| 45 |
-
### 3. Jupyter Notebooks 📓
|
| 46 |
-
The model is trained on Jupyter notebooks as Python scripts and structured formats like:
|
| 47 |
-
|
| 48 |
-
```
|
| 49 |
-
<start_jupyter><jupyter_text>text<jupyter_code>code<jupyter_output>output<jupyter_text>
|
| 50 |
-
```
|
| 51 |
-
|
| 52 |
-
### 4. Issues 🐛
|
| 53 |
-
We also trained on GitHub issues using the following formatting:
|
| 54 |
-
```
|
| 55 |
-
<issue_start><issue_comment>text<issue_comment>...<issue_closed>
|
| 56 |
-
```
|
| 57 |
-
|
| 58 |
-
### 5. Fill-in-the-middle 🧩
|
| 59 |
-
Fill in the middle requires rearranging the model inputs. The playground handles this for you - all you need is to specify where to fill:
|
| 60 |
-
```
|
| 61 |
-
code before<FILL_HERE>code after
|
| 62 |
-
```
|
| 63 |
-
"""
|
| 64 |
|
| 65 |
theme = gr.themes.Monochrome(
|
| 66 |
primary_hue="indigo",
|
|
@@ -87,7 +45,7 @@ client_plus = Client(
|
|
| 87 |
)
|
| 88 |
|
| 89 |
def generate(
|
| 90 |
-
prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
| 91 |
):
|
| 92 |
|
| 93 |
temperature = float(temperature)
|
|
@@ -113,12 +71,9 @@ def generate(
|
|
| 113 |
raise ValueError(f"Only one {FIM_INDICATOR} allowed in prompt!")
|
| 114 |
prompt = f"{FIM_PREFIX}{prefix}{FIM_SUFFIX}{suffix}{FIM_MIDDLE}"
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
stream = client_plus.generate_stream(prompt, **generate_kwargs)
|
| 120 |
-
else:
|
| 121 |
-
stream = client_base.generate_stream(prompt, **generate_kwargs)
|
| 122 |
|
| 123 |
if fim_mode:
|
| 124 |
output = prefix
|
|
@@ -164,34 +119,19 @@ monospace_css = """
|
|
| 164 |
|
| 165 |
css += share_btn_css + monospace_css + ".gradio-container {color: black}"
|
| 166 |
|
| 167 |
-
|
| 168 |
description = """
|
| 169 |
<div style="text-align: center;">
|
| 170 |
-
<h1>
|
| 171 |
</div>
|
| 172 |
<div style="text-align: left;">
|
| 173 |
-
<p>This is a demo to generate text and code with the following
|
| 174 |
-
<
|
| 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>\
|
| 183 |
-
<br>**Intended Use**: this app and its [supporting model](https://huggingface.co/bigcode) are provided for demonstration purposes; not to serve as replacement for human expertise. For more details on the model's limitations in terms of factuality and biases, see the [model card.](hf.co/bigcode)"""
|
| 184 |
|
| 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="StarCoder",
|
| 192 |
-
label="Model",
|
| 193 |
-
info="Choose a model from the list",
|
| 194 |
-
)
|
| 195 |
with gr.Row():
|
| 196 |
with gr.Column():
|
| 197 |
instruction = gr.Textbox(
|
|
@@ -246,7 +186,6 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
|
| 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)
|
| 252 |
loading_icon = gr.HTML(loading_icon_html, visible=True)
|
|
@@ -260,11 +199,10 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
|
| 260 |
fn=process_example,
|
| 261 |
outputs=[output],
|
| 262 |
)
|
| 263 |
-
gr.Markdown(FORMATS)
|
| 264 |
|
| 265 |
submit.click(
|
| 266 |
generate,
|
| 267 |
-
inputs=[instruction, temperature, max_new_tokens, top_p, repetition_penalty
|
| 268 |
outputs=[output],
|
| 269 |
)
|
| 270 |
share_button.click(None, [], [], _js=share_js)
|
|
|
|
| 11 |
|
| 12 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 13 |
|
| 14 |
+
API_URL = "https://api-inference.huggingface.co/models/codellama/CodeLlama-7b-hf"
|
|
|
|
|
|
|
| 15 |
|
| 16 |
FIM_PREFIX = "<fim_prefix>"
|
| 17 |
FIM_MIDDLE = "<fim_middle>"
|
|
|
|
| 19 |
|
| 20 |
FIM_INDICATOR = "<FILL_HERE>"
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
theme = gr.themes.Monochrome(
|
| 24 |
primary_hue="indigo",
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
def generate(
|
| 48 |
+
prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
| 49 |
):
|
| 50 |
|
| 51 |
temperature = float(temperature)
|
|
|
|
| 71 |
raise ValueError(f"Only one {FIM_INDICATOR} allowed in prompt!")
|
| 72 |
prompt = f"{FIM_PREFIX}{prefix}{FIM_SUFFIX}{suffix}{FIM_MIDDLE}"
|
| 73 |
|
| 74 |
+
|
| 75 |
+
stream = client.generate_stream(prompt, **generate_kwargs)
|
| 76 |
+
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
if fim_mode:
|
| 79 |
output = prefix
|
|
|
|
| 119 |
|
| 120 |
css += share_btn_css + monospace_css + ".gradio-container {color: black}"
|
| 121 |
|
|
|
|
| 122 |
description = """
|
| 123 |
<div style="text-align: center;">
|
| 124 |
+
<h1> 🦙 CodeLlama Playground</h1>
|
| 125 |
</div>
|
| 126 |
<div style="text-align: left;">
|
| 127 |
+
<p>This is a demo to generate text and code with the following Code Llama model (7B).</p>
|
| 128 |
+
<p><b>Please note:</b> This model is not designed for instruction purposes but for code completion. If you're looking for instruction or want to chat with a fine-tuned model, you can visit the <a href="https://huggingface.co/codellama/">Code Llama Org</a> and select an instruct model.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
</div>
|
| 130 |
"""
|
|
|
|
|
|
|
| 131 |
|
| 132 |
with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
| 133 |
with gr.Column():
|
| 134 |
gr.Markdown(description)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
with gr.Row():
|
| 136 |
with gr.Column():
|
| 137 |
instruction = gr.Textbox(
|
|
|
|
| 186 |
info="Penalize repeated tokens",
|
| 187 |
)
|
| 188 |
|
|
|
|
| 189 |
with gr.Group(elem_id="share-btn-container"):
|
| 190 |
community_icon = gr.HTML(community_icon_html, visible=True)
|
| 191 |
loading_icon = gr.HTML(loading_icon_html, visible=True)
|
|
|
|
| 199 |
fn=process_example,
|
| 200 |
outputs=[output],
|
| 201 |
)
|
|
|
|
| 202 |
|
| 203 |
submit.click(
|
| 204 |
generate,
|
| 205 |
+
inputs=[instruction, temperature, max_new_tokens, top_p, repetition_penalty],
|
| 206 |
outputs=[output],
|
| 207 |
)
|
| 208 |
share_button.click(None, [], [], _js=share_js)
|