Spaces:
Sleeping
Sleeping
Update app10.py
Browse files
app10.py
CHANGED
@@ -128,6 +128,7 @@ if task_choice == "Data Generation":
|
|
128 |
st.error("An error occurred during generation.")
|
129 |
st.error(f"Details: {e}")
|
130 |
|
|
|
131 |
elif task_choice == "Data Labeling":
|
132 |
# Labeling logic
|
133 |
labeling_type = st.selectbox(
|
@@ -158,14 +159,31 @@ elif task_choice == "Data Labeling":
|
|
158 |
|
159 |
if st.button("Classify Text"):
|
160 |
if text_to_classify:
|
161 |
-
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
)
|
|
|
|
|
|
|
164 |
if few_shot_labeling_examples:
|
165 |
-
|
166 |
for ex in few_shot_labeling_examples:
|
167 |
-
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
with st.spinner("Classifying..."):
|
171 |
st.session_state.messages.append({"role": "system", "content": labeling_prompt})
|
@@ -178,7 +196,9 @@ elif task_choice == "Data Labeling":
|
|
178 |
max_tokens=3000,
|
179 |
)
|
180 |
labeling_response = st.write_stream(stream)
|
181 |
-
|
|
|
|
|
182 |
except Exception as e:
|
183 |
st.error("An error occurred during classification.")
|
184 |
st.error(f"Details: {e}")
|
|
|
128 |
st.error("An error occurred during generation.")
|
129 |
st.error(f"Details: {e}")
|
130 |
|
131 |
+
|
132 |
elif task_choice == "Data Labeling":
|
133 |
# Labeling logic
|
134 |
labeling_type = st.selectbox(
|
|
|
159 |
|
160 |
if st.button("Classify Text"):
|
161 |
if text_to_classify:
|
162 |
+
# Construct the labeling prompt
|
163 |
+
labeling_prompt_template = PromptTemplate(
|
164 |
+
input_variables=["labeling_type", "labels", "few_shot_examples", "text_to_classify"],
|
165 |
+
template=(
|
166 |
+
"You are an expert in {labeling_type} classification. "
|
167 |
+
"Classify the following text using: {labels}.\n\n"
|
168 |
+
"{few_shot_examples}\n"
|
169 |
+
"Classify this: {text_to_classify}"
|
170 |
+
)
|
171 |
)
|
172 |
+
|
173 |
+
# Prepare few-shot examples for the prompt
|
174 |
+
few_shot_examples_text = ""
|
175 |
if few_shot_labeling_examples:
|
176 |
+
few_shot_examples_text += "Example classifications:\n"
|
177 |
for ex in few_shot_labeling_examples:
|
178 |
+
few_shot_examples_text += f"Text: {ex['content']} - Label: {ex['label']}\n"
|
179 |
+
|
180 |
+
# Format the prompt with the user's input
|
181 |
+
labeling_prompt = labeling_prompt_template.format(
|
182 |
+
labeling_type=labeling_type.lower(),
|
183 |
+
labels=", ".join(labels),
|
184 |
+
few_shot_examples=few_shot_examples_text.strip(),
|
185 |
+
text_to_classify=text_to_classify
|
186 |
+
)
|
187 |
|
188 |
with st.spinner("Classifying..."):
|
189 |
st.session_state.messages.append({"role": "system", "content": labeling_prompt})
|
|
|
196 |
max_tokens=3000,
|
197 |
)
|
198 |
labeling_response = st.write_stream(stream)
|
199 |
+
# Format response to match desired output
|
200 |
+
formatted_response = f"Label: {labeling_response}"
|
201 |
+
st.write(formatted_response)
|
202 |
except Exception as e:
|
203 |
st.error("An error occurred during classification.")
|
204 |
st.error(f"Details: {e}")
|