Spaces:
Runtime error
Runtime error
Commit
·
9d2dbc7
1
Parent(s):
3573b23
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import shutil
|
4 |
+
import gradio as gr
|
5 |
+
from datasets import load_dataset
|
6 |
+
from huggingface_hub import Repository
|
7 |
+
|
8 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
9 |
+
|
10 |
+
def load_data():
|
11 |
+
dataset = load_dataset("ArmelR/oasst1_guanaco_english", use_auth_token=HF_TOKEN)
|
12 |
+
return dataset
|
13 |
+
|
14 |
+
samples = load_data()
|
15 |
+
splits = list(samples.keys())
|
16 |
+
languages = ["Wolof"]
|
17 |
+
|
18 |
+
custom_css = """
|
19 |
+
#banner-image {
|
20 |
+
display: block;
|
21 |
+
margin-left: auto;
|
22 |
+
margin-right: auto;
|
23 |
+
}
|
24 |
+
#chat-message {
|
25 |
+
font-size: 14px;
|
26 |
+
min-height: 300px;
|
27 |
+
}
|
28 |
+
"""
|
29 |
+
def caller_split(s):
|
30 |
+
return 0, samples[s][0]["prompt"], samples[s][0]["completion"]
|
31 |
+
|
32 |
+
def identity(index, split):
|
33 |
+
ds = samples[split][index]
|
34 |
+
return ds["prompt"], ds["completion"]
|
35 |
+
|
36 |
+
def save(index, language, split, prompt, completion):
|
37 |
+
with open("./output.jsonl", "a") as fout :
|
38 |
+
fout.write(
|
39 |
+
json.dumps(
|
40 |
+
{
|
41 |
+
"prompt" : prompt,
|
42 |
+
"completion" : completion,
|
43 |
+
"language" : language,
|
44 |
+
"index" : index
|
45 |
+
}
|
46 |
+
)+"\n"
|
47 |
+
)
|
48 |
+
next_index = min(1+index, len(samples[split]-1))
|
49 |
+
return next_index, ds[split][next_index]["prompt"], ds[split][next_index]["completion"]
|
50 |
+
|
51 |
+
with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
52 |
+
gr.HTML("""<h1 align="center">Self-instruct StarCoder 💫</h1>""")
|
53 |
+
gr.Markdown(
|
54 |
+
"""
|
55 |
+
This space provides a visualization tool for the samples from this [dataset](https://huggingface.co/datasets/codeparrot/self-instruct-starcoder) generated by applying
|
56 |
+
the self-instruct procedure to Starcoder💫. For each instruction, we have its ouput, as well as some instructions generated along the way that are similar to it with the corresponding
|
57 |
+
score.
|
58 |
+
"""
|
59 |
+
)
|
60 |
+
with gr.Row() :
|
61 |
+
split = gr.Dropdown(choices=splits, label="Dataset split", value=splits[0])
|
62 |
+
with gr.Row() :
|
63 |
+
index_example = gr.Slider(minimum=0, maximum=10000, step=1, value=0, interactive=True, info=f"Index of the chosen instruction-output pair.")
|
64 |
+
with gr.Column():
|
65 |
+
prompt = gr.Textbox(label="prompt")
|
66 |
+
with gr.Column()
|
67 |
+
completion = gr.Textbox(label="Completion")
|
68 |
+
with gr.Row() :
|
69 |
+
language = gr.Dropdown(choices=splits, label="Translation language", value=languages[0])
|
70 |
+
with gr.Column() :
|
71 |
+
translated_prompt = gr.Textbox(label="Translated prompt")
|
72 |
+
with gr.Column() :
|
73 |
+
translated_completion = gr.Textbox(label="Translated completion")
|
74 |
+
with gr.Row() :
|
75 |
+
button = gr.Button(value="Submit")
|
76 |
+
|
77 |
+
split.change(caller_split, inputs=[split], outputs=[index_example, prompt, completion])
|
78 |
+
index_example.release(identity, inputs=[index_example, split], outputs=[prompt, completion])
|
79 |
+
btn.click(save, inputs=[index_example, language, split, translated_prompt, translated_completion], outputs=[index_example, prompt, completion])
|
80 |
+
|
81 |
+
demo.queue(concurrency_count=16).launch(debug=True)
|