Spaces:
Running
Running
Commit
Β·
8a4dd4f
1
Parent(s):
ae3b26c
update.
Browse files- app.py +127 -73
- assets/examples.json +54 -0
app.py
CHANGED
@@ -10,7 +10,7 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
10 |
import streamlit as st
|
11 |
import pandas as pd
|
12 |
import base64
|
13 |
-
|
14 |
|
15 |
@st.cache_data
|
16 |
def render_svg(svg):
|
@@ -31,12 +31,22 @@ def load_tokenizer(model_name):
|
|
31 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
32 |
return tokenizer
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
with st.spinner(text="Please wait while the model is loading...."):
|
35 |
|
36 |
model = load_model('nafisehNik/girt-t5-base')
|
37 |
tokenizer = load_tokenizer('nafisehNik/girt-t5-base')
|
|
|
38 |
|
39 |
|
|
|
40 |
def create_instruction(name, about, title, labels, assignees, headline_type, headline, summary):
|
41 |
value_list = [name, about, title, labels, assignees, headline_type, headline]
|
42 |
|
@@ -47,6 +57,7 @@ def create_instruction(name, about, title, labels, assignees, headline_type, hea
|
|
47 |
instruction = f'name: {value_list[0]}\nabout: {value_list[1]}\ntitle: {value_list[2]}\nlabels: {value_list[3]}\nassignees: {value_list[4]}\nheadlines_type: {value_list[5]}\nheadlines: {value_list[6]}\nsummary: {summary}'
|
48 |
return instruction
|
49 |
|
|
|
50 |
def compute(sample, top_p, top_k, do_sample, max_length, min_length):
|
51 |
|
52 |
inputs = tokenizer(sample, return_tensors="pt").to('cpu')
|
@@ -77,10 +88,13 @@ def compute(sample, top_p, top_k, do_sample, max_length, min_length):
|
|
77 |
|
78 |
return postprocess_text
|
79 |
|
|
|
80 |
st.markdown("[](https://huggingface.co/spaces/nafisehNik/girt-space?duplicate=true)")
|
81 |
|
|
|
82 |
render_svg(open("assets/logo.svg").read())
|
83 |
|
|
|
84 |
st.markdown(
|
85 |
"""
|
86 |
<style>
|
@@ -96,35 +110,113 @@ with st.sidebar:
|
|
96 |
st.title(" π§ Settings")
|
97 |
|
98 |
with st.expander("π Issue Template Inputs", True):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
-
|
104 |
-
if
|
105 |
-
|
106 |
else:
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
if
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
else:
|
113 |
in_labels = '<|EMPTY|>'
|
114 |
|
115 |
-
|
116 |
-
if
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
else:
|
119 |
in_assignees = '<|EMPTY|>'
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
# if no headlines is selected, force the headlines to be empty as well.
|
122 |
in_headline_type = st.selectbox(
|
123 |
-
'How would you like to be your Headlines?',
|
124 |
-
('**Emphasis**', '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
if in_headline_type!='No headlines':
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
if not in_headlines:
|
130 |
in_headlines = '<|MASK|>'
|
@@ -132,19 +224,16 @@ with st.sidebar:
|
|
132 |
in_headlines = in_headlines.split('\n')
|
133 |
in_headlines = [element.strip() for element in in_headlines]
|
134 |
|
135 |
-
else:
|
136 |
-
in_headline_type = '<|EMPTY|>'
|
137 |
-
in_headlines = '<|EMPTY|>'
|
138 |
|
139 |
-
#
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
-
in_summary = st.text_area("Summary: ", placeholder="This Github Issue Template is ...", on_change=None, height=200)
|
144 |
-
|
145 |
-
in_examples = st.selectbox(
|
146 |
-
'Select one of the following examples or implement yours:',
|
147 |
-
('Example 1', 'Example 2', 'Example 3', 'Example 4'))
|
148 |
|
149 |
with st.expander("π Model Configs", False):
|
150 |
max_length_in = st.slider("max_length", 30, 512, 300)
|
@@ -154,51 +243,16 @@ with st.sidebar:
|
|
154 |
|
155 |
|
156 |
|
157 |
-
|
158 |
-
|
159 |
-
with tab1:
|
160 |
-
|
161 |
-
clicked_2 = st.button("Submit", key='pr-sub')
|
162 |
-
if clicked_2:
|
163 |
-
prompt = create_instruction(in_name, in_about, in_title, in_labels, in_assignees, in_headline_type, in_headlines, in_summary)
|
164 |
-
st.code(prompt, language="python")
|
165 |
-
with st.spinner("Please Wait..."):
|
166 |
-
res = compute(prompt, top_p = top_p_in, top_k=top_k_in, do_sample=True, max_length=max_length_in, min_length=min_length_in)
|
167 |
-
st.code(res, language="python")
|
168 |
-
|
169 |
-
# template_prompt = "name:"
|
170 |
-
# filled_prompt = "name:"
|
171 |
-
|
172 |
-
# clicked = st.button("Submit", key='design')
|
173 |
-
|
174 |
-
# with st.spinner("Please Wait..."):
|
175 |
-
|
176 |
-
# if filled_prompt!=template_prompt:
|
177 |
-
# res = compute(prompt, top_p=0.92, top_k=0, do_sample=True, max_length=300, min_length=0)
|
178 |
-
# st.code(res, language="python")
|
179 |
-
# prompt = create_instruction(in_name, in_about, in_title, in_labels, in_assignees, in_headline_type, in_headlines, in_summary)
|
180 |
|
181 |
-
|
|
|
|
|
|
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
# res = compute(prompt, top_p = top_p_in, top_k=top_k_in, do_sample=True, max_length=max_length_in, min_length=min_length_in)
|
186 |
-
# st.code(res, language="python")
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
with tab2:
|
191 |
-
|
192 |
-
st.markdown('This part is only based on the prompt you provide here and not the issue template inputs.')
|
193 |
-
|
194 |
-
prompt = st.text_area("Prompt: ", placeholder="Enter your prompt.", on_change=None, height=200)
|
195 |
-
|
196 |
-
clicked = st.button("Submit", key='prompt')
|
197 |
|
|
|
198 |
with st.spinner("Please Wait..."):
|
199 |
-
|
200 |
-
|
201 |
-
res = compute(prompt, top_p=0.92, top_k=0, do_sample=True, max_length=300, min_length=0)
|
202 |
-
st.code(res, language="python")
|
203 |
-
|
204 |
-
|
|
|
10 |
import streamlit as st
|
11 |
import pandas as pd
|
12 |
import base64
|
13 |
+
import json
|
14 |
|
15 |
@st.cache_data
|
16 |
def render_svg(svg):
|
|
|
31 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
32 |
return tokenizer
|
33 |
|
34 |
+
@st.cache_resource
|
35 |
+
def load_examples():
|
36 |
+
with open("assets/examples.json", "r") as f:
|
37 |
+
examples = json.load(f)
|
38 |
+
return examples
|
39 |
+
|
40 |
+
|
41 |
+
# load resources
|
42 |
with st.spinner(text="Please wait while the model is loading...."):
|
43 |
|
44 |
model = load_model('nafisehNik/girt-t5-base')
|
45 |
tokenizer = load_tokenizer('nafisehNik/girt-t5-base')
|
46 |
+
examples = load_examples()
|
47 |
|
48 |
|
49 |
+
# create instruction from metadata
|
50 |
def create_instruction(name, about, title, labels, assignees, headline_type, headline, summary):
|
51 |
value_list = [name, about, title, labels, assignees, headline_type, headline]
|
52 |
|
|
|
57 |
instruction = f'name: {value_list[0]}\nabout: {value_list[1]}\ntitle: {value_list[2]}\nlabels: {value_list[3]}\nassignees: {value_list[4]}\nheadlines_type: {value_list[5]}\nheadlines: {value_list[6]}\nsummary: {summary}'
|
58 |
return instruction
|
59 |
|
60 |
+
# compute the output
|
61 |
def compute(sample, top_p, top_k, do_sample, max_length, min_length):
|
62 |
|
63 |
inputs = tokenizer(sample, return_tensors="pt").to('cpu')
|
|
|
88 |
|
89 |
return postprocess_text
|
90 |
|
91 |
+
# load deduplicate icon
|
92 |
st.markdown("[](https://huggingface.co/spaces/nafisehNik/girt-space?duplicate=true)")
|
93 |
|
94 |
+
# load logo
|
95 |
render_svg(open("assets/logo.svg").read())
|
96 |
|
97 |
+
# exapnd sidebar
|
98 |
st.markdown(
|
99 |
"""
|
100 |
<style>
|
|
|
110 |
st.title(" π§ Settings")
|
111 |
|
112 |
with st.expander("π Issue Template Inputs", True):
|
113 |
+
|
114 |
+
# choose examples
|
115 |
+
in_examples = st.selectbox(
|
116 |
+
label = 'You can select one of the following examples and customize it:',
|
117 |
+
options = ('no example', 'bug report', 'feature request', 'question', 'documentation'),
|
118 |
+
index = 1)
|
119 |
+
|
120 |
+
in_name = st.text_input(
|
121 |
+
label = "Name Metadata: ",
|
122 |
+
value = examples[in_examples]['name'],
|
123 |
+
placeholder="e.g., Bug Report or Feqture Request or Question",
|
124 |
+
on_change = None)
|
125 |
|
126 |
+
in_about = st.text_input(
|
127 |
+
label = "About Metadata: ",
|
128 |
+
value = examples[in_examples]['about'],
|
129 |
+
placeholder="e.g., File a bug report",
|
130 |
+
on_change=None)
|
131 |
+
|
132 |
+
# Title
|
133 |
+
if examples[in_examples]['title'] == '<|EMPTY|>':
|
134 |
+
empty_title_value_default = True
|
135 |
+
else:
|
136 |
+
empty_title_value_default = False
|
137 |
+
in_empty_title = st.checkbox(label ='without title', value = empty_title_value_default)
|
138 |
+
|
139 |
+
if in_empty_title == False:
|
140 |
+
# check if the example title is actually not empty
|
141 |
+
title_value_default = examples[in_examples]['title'] if examples[in_examples]['title'] != '<|EMPTY|>' else ""
|
142 |
+
in_title = st.text_input(
|
143 |
+
label = "Title Metadata: ",
|
144 |
+
value = title_value_default,
|
145 |
+
placeholder="e.g., [Bug]: ",
|
146 |
+
on_change=None)
|
147 |
+
else:
|
148 |
+
in_title = '<|EMPTY|>'
|
149 |
|
150 |
+
# Labels
|
151 |
+
if examples[in_examples]['labels'] == '<|EMPTY|>':
|
152 |
+
empty_labels_value_default = True
|
153 |
else:
|
154 |
+
empty_labels_value_default = False
|
155 |
+
in_empty_labels = st.checkbox(label ='without labels', value = empty_labels_value_default)
|
156 |
+
|
157 |
+
if in_empty_labels == False:
|
158 |
+
# check if the example labels is actually not empty
|
159 |
+
labels_value_default = examples[in_examples]['labels'] if examples[in_examples]['labels'] != '<|EMPTY|>' else ""
|
160 |
+
in_labels = st.text_input(
|
161 |
+
label = "Labels Metadata: ",
|
162 |
+
value = labels_value_default,
|
163 |
+
placeholder="e.g., feature, enhancement",
|
164 |
+
on_change=None)
|
165 |
else:
|
166 |
in_labels = '<|EMPTY|>'
|
167 |
|
168 |
+
# Assignees
|
169 |
+
if examples[in_examples]['assignees'] == '<|EMPTY|>':
|
170 |
+
empty_assignees_value_default = True
|
171 |
+
else:
|
172 |
+
empty_assignees_value_default = False
|
173 |
+
in_empty_assignees = st.checkbox(label ='without assignees', value = empty_assignees_value_default)
|
174 |
+
|
175 |
+
if in_empty_assignees == False:
|
176 |
+
# check if the example assignees is actually not empty
|
177 |
+
assignees_value_default = examples[in_examples]['assignees'] if examples[in_examples]['assignees'] != '<|EMPTY|>' else ""
|
178 |
+
in_assignees = st.text_input(
|
179 |
+
label = "Assignees Metadata: ",
|
180 |
+
value = assignees_value_default,
|
181 |
+
placeholder="e.g., feature, enhancement",
|
182 |
+
on_change=None)
|
183 |
else:
|
184 |
in_assignees = '<|EMPTY|>'
|
185 |
+
|
186 |
+
# headline type
|
187 |
+
if examples[in_examples]['headlines_type'] == '<|EMPTY|>':
|
188 |
+
headlines_type_value_default = 3
|
189 |
+
elif examples[in_examples]['headlines_type'] == '':
|
190 |
+
headlines_type_value_default = 2
|
191 |
+
elif examples[in_examples]['headlines_type'] == '**Emphasis**':
|
192 |
+
headlines_type_value_default = 1
|
193 |
+
else:
|
194 |
+
headlines_type_value_default = 0
|
195 |
+
|
196 |
# if no headlines is selected, force the headlines to be empty as well.
|
197 |
in_headline_type = st.selectbox(
|
198 |
+
label = 'How would you like to be your Headlines?',
|
199 |
+
options = ('# Heading', '**Emphasis**', 'Either', 'No headlines'),
|
200 |
+
index = headlines_type_value_default)
|
201 |
+
|
202 |
+
if in_headline_type == 'Either':
|
203 |
+
in_headline_type = '<|MASK|>'
|
204 |
+
|
205 |
+
if in_headline_type == 'No headlines':
|
206 |
+
in_headline_type = '<|EMPTY|>'
|
207 |
+
in_headlines = '<|EMPTY|>'
|
208 |
+
|
209 |
|
210 |
if in_headline_type!='No headlines':
|
211 |
+
|
212 |
+
headlines_value_default = examples[in_examples]['headlines'] if examples[in_examples]['headlines'] != '<|EMPTY|>' else ""
|
213 |
+
|
214 |
+
in_headlines = st.text_area(
|
215 |
+
label = "Headlines: ",
|
216 |
+
value = headlines_value_default,
|
217 |
+
placeholder="Enter each headline in one line. e.g.,\nWelcome\nConcise Description\nAdditional Info",
|
218 |
+
on_change=None,
|
219 |
+
height=200)
|
220 |
|
221 |
if not in_headlines:
|
222 |
in_headlines = '<|MASK|>'
|
|
|
224 |
in_headlines = in_headlines.split('\n')
|
225 |
in_headlines = [element.strip() for element in in_headlines]
|
226 |
|
|
|
|
|
|
|
227 |
|
228 |
+
# summary
|
229 |
+
summary_value_default = examples[in_examples]['summary'] if examples[in_examples]['summary'] != '<|EMPTY|>' else ""
|
230 |
+
in_summary = st.text_area(
|
231 |
+
label = "Summary: ",
|
232 |
+
value = summary_value_default,
|
233 |
+
placeholder="This Github Issue Template is ...",
|
234 |
+
on_change=None,
|
235 |
+
height=200)
|
236 |
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
with st.expander("π Model Configs", False):
|
239 |
max_length_in = st.slider("max_length", 30, 512, 300)
|
|
|
243 |
|
244 |
|
245 |
|
246 |
+
prompt = create_instruction(in_name, in_about, in_title, in_labels, in_assignees, in_headline_type, in_headlines, in_summary)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
|
248 |
+
prompt_manual = st.text_area(
|
249 |
+
label = "Enter your prompt here.",
|
250 |
+
value = prompt,
|
251 |
+
placeholder=None)
|
252 |
|
253 |
+
clicked = st.button("Submit")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
|
255 |
+
if clicked:
|
256 |
with st.spinner("Please Wait..."):
|
257 |
+
res = compute(prompt_manual, top_p = top_p_in, top_k=top_k_in, do_sample=True, max_length=max_length_in, min_length=min_length_in)
|
258 |
+
st.code(res, language="python")
|
|
|
|
|
|
|
|
assets/examples.json
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bug report": {
|
3 |
+
"name": "Bug report",
|
4 |
+
"about": "Ask a question about the <|Repo_Name|>",
|
5 |
+
"title": "bug",
|
6 |
+
"labels": "",
|
7 |
+
"assignees": "<|EMPTY|>",
|
8 |
+
"headlines_type": "**Emphasis**",
|
9 |
+
"headlines": "['Description', 'Steps to reproduce', 'Expected behavior', 'Screenshot or video', 'Environment', 'version']",
|
10 |
+
"summary": "<|EMPTY|>"
|
11 |
+
|
12 |
+
},
|
13 |
+
"feature request": {
|
14 |
+
"name": "feature",
|
15 |
+
"about": "Suggest a feature for the <|Repo_Name|>",
|
16 |
+
"title": "<|EMPTY|>",
|
17 |
+
"labels": "<|EMPTY|>",
|
18 |
+
"assignees": "<|EMPTY|>",
|
19 |
+
"headlines_type": "# Heading",
|
20 |
+
"headlines": "",
|
21 |
+
"summary": "This Github issue template is designed to help users suggest features for the <|Repo_Name|>. Before submitting an issue, users should ensure they have checked the documentation and forums, verified that the feature has not already been proposed, and selected the correct repository for multi-repository projects. The feature description should be clear and concise, outlining the desired outcome and any related problems. Alternative solutions and screenshots may also be included."
|
22 |
+
|
23 |
+
},
|
24 |
+
"question": {
|
25 |
+
"name": "Question",
|
26 |
+
"about": "Ask a question about the <|Repo_Name|>",
|
27 |
+
"title": "<|EMPTY|>",
|
28 |
+
"labels": "kind/question",
|
29 |
+
"assignees": "<|EMPTY|>",
|
30 |
+
"headlines_type": "",
|
31 |
+
"headlines": "",
|
32 |
+
"summary": "This Github issue template is designed to encourage users to first check the documentation, search for answers online, and ask their colleagues for help before opening a new issue. If the user has already done these steps, they are encouraged to provide their question in the issue. The template includes three questions for the user to answer before opening the issue."
|
33 |
+
},
|
34 |
+
"documentation": {
|
35 |
+
"name": "documentation",
|
36 |
+
"about": "",
|
37 |
+
"title": "[Doc]",
|
38 |
+
"labels": "docs",
|
39 |
+
"assignees": "<|EMPTY|>",
|
40 |
+
"headlines_type": "# Heading",
|
41 |
+
"headlines": "['Documentation Scope', 'Describe the Change', 'Screenshots', 'Additional context']",
|
42 |
+
"summary": "This Github issue template is for adding or updating documentation. The documentation can be for various things, such as the homepage, getting started, or user manuals."
|
43 |
+
},
|
44 |
+
"no example": {
|
45 |
+
"name": "",
|
46 |
+
"about": "",
|
47 |
+
"title": "",
|
48 |
+
"labels": "",
|
49 |
+
"assignees": "",
|
50 |
+
"headlines_type": "# Heading",
|
51 |
+
"headlines": "",
|
52 |
+
"summary": ""
|
53 |
+
}
|
54 |
+
}
|