Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,12 @@ HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
|
12 |
API_URL = os.environ.get("API_URL")
|
13 |
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
theme = gr.themes.Monochrome(
|
16 |
primary_hue="indigo",
|
17 |
secondary_hue="blue",
|
@@ -25,34 +31,44 @@ client = Client(
|
|
25 |
#headers={"Authorization": f"Bearer {HF_TOKEN}"},
|
26 |
)
|
27 |
|
28 |
-
|
29 |
def generate(prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
30 |
|
31 |
temperature = float(temperature)
|
32 |
if temperature < 1e-2:
|
33 |
temperature = 1e-2
|
34 |
top_p = float(top_p)
|
35 |
-
|
|
|
36 |
generate_kwargs = dict(
|
37 |
temperature=temperature,
|
38 |
max_new_tokens=max_new_tokens,
|
39 |
top_p=top_p,
|
40 |
repetition_penalty=repetition_penalty,
|
41 |
do_sample=True,
|
42 |
-
truncate=999,
|
43 |
seed=42,
|
44 |
-
stop_sequences=["</s>"],
|
45 |
)
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
output = prompt
|
53 |
for response in stream:
|
54 |
output += response.token.text
|
55 |
yield output
|
|
|
|
|
|
|
56 |
return output
|
57 |
|
58 |
|
@@ -74,7 +90,33 @@ css = ".generating {visibility: hidden}" + share_btn_css
|
|
74 |
with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
75 |
with gr.Column():
|
76 |
gr.Markdown(
|
77 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
"""
|
79 |
)
|
80 |
with gr.Row():
|
@@ -107,7 +149,7 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
|
107 |
label="Max new tokens",
|
108 |
value=256,
|
109 |
minimum=0,
|
110 |
-
maximum=
|
111 |
step=4,
|
112 |
interactive=True,
|
113 |
info="The maximum numbers of new tokens",
|
|
|
12 |
API_URL = os.environ.get("API_URL")
|
13 |
|
14 |
|
15 |
+
FIM_PREFIX = "<fim_prefix>"
|
16 |
+
FIM_MIDDLE = "<fim_middle>"
|
17 |
+
FIM_SUFFIX = "<fim_suffix>"
|
18 |
+
|
19 |
+
FIM_INDICATOR = "<FILL_HERE>"
|
20 |
+
|
21 |
theme = gr.themes.Monochrome(
|
22 |
primary_hue="indigo",
|
23 |
secondary_hue="blue",
|
|
|
31 |
#headers={"Authorization": f"Bearer {HF_TOKEN}"},
|
32 |
)
|
33 |
|
|
|
34 |
def generate(prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
35 |
|
36 |
temperature = float(temperature)
|
37 |
if temperature < 1e-2:
|
38 |
temperature = 1e-2
|
39 |
top_p = float(top_p)
|
40 |
+
fim_mode = False
|
41 |
+
|
42 |
generate_kwargs = dict(
|
43 |
temperature=temperature,
|
44 |
max_new_tokens=max_new_tokens,
|
45 |
top_p=top_p,
|
46 |
repetition_penalty=repetition_penalty,
|
47 |
do_sample=True,
|
|
|
48 |
seed=42,
|
|
|
49 |
)
|
50 |
|
51 |
+
if FIM_INDICATOR in prompt:
|
52 |
+
fim_mode = True
|
53 |
+
try:
|
54 |
+
prefix, suffix = prompt.split("<FILL-HERE>")
|
55 |
+
except:
|
56 |
+
ValueError("Only one <FILL-HERE> allowed in prompt!")
|
57 |
+
prompt = f"{FIM_PREFIX}{prefix}{FIM_SUFFIX}{suffix}{FIM_MIDDLE}"
|
58 |
+
|
59 |
+
stream = client.generate_stream(prompt, **generate_kwargs)
|
60 |
+
|
61 |
+
if fim_mode:
|
62 |
+
output = prefix
|
63 |
+
else:
|
64 |
+
output = prompt
|
65 |
|
|
|
66 |
for response in stream:
|
67 |
output += response.token.text
|
68 |
yield output
|
69 |
+
|
70 |
+
if fim_mode:
|
71 |
+
output += suffix
|
72 |
return output
|
73 |
|
74 |
|
|
|
90 |
with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
91 |
with gr.Column():
|
92 |
gr.Markdown(
|
93 |
+
"""\
|
94 |
+
# BigCode - Playground
|
95 |
+
_Note:_ this is an internal playground - please do not share. The deployment can also change and thus the space not work as we continue development.
|
96 |
+
|
97 |
+
## Model formats
|
98 |
+
|
99 |
+
### Prefixes
|
100 |
+
Any combination of the three:
|
101 |
+
```
|
102 |
+
<reponame>REPONAME<filename>FILENAME<gh_stars>STARS\nCode<eos>
|
103 |
+
```
|
104 |
+
Stars be: 0, 1-10, 10-100, 100-1000, 1000+
|
105 |
+
|
106 |
+
### Commits
|
107 |
+
```
|
108 |
+
<commit_before>code<commit_msg>text<commit_after>code<|endoftext|>
|
109 |
+
```
|
110 |
+
|
111 |
+
### Jupyter structure
|
112 |
+
```
|
113 |
+
<start_jupyter><jupyter_text>text<jupyter_code>code<jupyter_output>output<jupyter_text>
|
114 |
+
```
|
115 |
+
|
116 |
+
### Fill-in-the-middle
|
117 |
+
```
|
118 |
+
code before<FILL_HERE>code after
|
119 |
+
```
|
120 |
"""
|
121 |
)
|
122 |
with gr.Row():
|
|
|
149 |
label="Max new tokens",
|
150 |
value=256,
|
151 |
minimum=0,
|
152 |
+
maximum=4096,
|
153 |
step=4,
|
154 |
interactive=True,
|
155 |
info="The maximum numbers of new tokens",
|