Update app.py
Browse files
app.py
CHANGED
@@ -91,28 +91,29 @@ if task_choice == "Data Generation":
|
|
91 |
num_to_generate = st.number_input("How many examples to generate?", min_value=1, max_value=50, value=10)
|
92 |
|
93 |
# System prompt generation
|
94 |
-
system_prompt = f"You are a professional {classification_type.lower()} expert. Your role is to generate data for {domain}
|
|
|
|
|
|
|
95 |
if few_shot_examples:
|
96 |
system_prompt += "Use the following few-shot examples as a reference:\n"
|
97 |
for example in few_shot_examples:
|
98 |
system_prompt += f"Example: {example['content']}, Label: {example['label']}\n"
|
99 |
-
|
100 |
-
system_prompt += "
|
|
|
101 |
|
102 |
st.write("System Prompt:")
|
103 |
st.code(system_prompt)
|
104 |
|
105 |
if st.button("Generate Examples"):
|
106 |
-
# Break generation into smaller chunks if needed to ensure enough examples
|
107 |
all_generated_examples = []
|
108 |
remaining_examples = num_to_generate
|
109 |
|
110 |
with st.spinner("Generating..."):
|
111 |
while remaining_examples > 0:
|
112 |
-
# Generating examples in chunks to avoid token limits
|
113 |
chunk_size = min(remaining_examples, 5)
|
114 |
try:
|
115 |
-
# Append the new chunk system prompt
|
116 |
st.session_state.messages.append({"role": "system", "content": system_prompt})
|
117 |
|
118 |
stream = client.chat.completions.create(
|
@@ -126,9 +127,10 @@ if task_choice == "Data Generation":
|
|
126 |
max_tokens=3000,
|
127 |
)
|
128 |
|
129 |
-
# Parse the response and break it into individual examples
|
130 |
response = st.write_stream(stream)
|
131 |
-
|
|
|
|
|
132 |
|
133 |
# Store the new examples
|
134 |
all_generated_examples.extend(generated_examples)
|
@@ -141,7 +143,7 @@ if task_choice == "Data Generation":
|
|
141 |
|
142 |
# Display all generated examples
|
143 |
for idx, example in enumerate(all_generated_examples):
|
144 |
-
st.write(f"Example {idx+1}: {example}")
|
145 |
|
146 |
# Update session state to prevent repetition of old prompts
|
147 |
st.session_state.messages = [] # Clear messages after each generation
|
|
|
91 |
num_to_generate = st.number_input("How many examples to generate?", min_value=1, max_value=50, value=10)
|
92 |
|
93 |
# System prompt generation
|
94 |
+
system_prompt = f"You are a professional {classification_type.lower()} expert. Your role is to generate {num_to_generate} data examples for {domain}. "
|
95 |
+
system_prompt += f"Each example should have a label and consist of between {min_words} and {max_words} words. "
|
96 |
+
system_prompt += "Use the following labels: " + ", ".join(labels) + ". "
|
97 |
+
|
98 |
if few_shot_examples:
|
99 |
system_prompt += "Use the following few-shot examples as a reference:\n"
|
100 |
for example in few_shot_examples:
|
101 |
system_prompt += f"Example: {example['content']}, Label: {example['label']}\n"
|
102 |
+
|
103 |
+
system_prompt += "Please only provide the examples in the following format:\n"
|
104 |
+
system_prompt += "Example: <text>, Label: <label>\n"
|
105 |
|
106 |
st.write("System Prompt:")
|
107 |
st.code(system_prompt)
|
108 |
|
109 |
if st.button("Generate Examples"):
|
|
|
110 |
all_generated_examples = []
|
111 |
remaining_examples = num_to_generate
|
112 |
|
113 |
with st.spinner("Generating..."):
|
114 |
while remaining_examples > 0:
|
|
|
115 |
chunk_size = min(remaining_examples, 5)
|
116 |
try:
|
|
|
117 |
st.session_state.messages.append({"role": "system", "content": system_prompt})
|
118 |
|
119 |
stream = client.chat.completions.create(
|
|
|
127 |
max_tokens=3000,
|
128 |
)
|
129 |
|
|
|
130 |
response = st.write_stream(stream)
|
131 |
+
|
132 |
+
# Split the response into individual examples, assuming each example starts with 'Example: '
|
133 |
+
generated_examples = response.split("Example: ")[1:chunk_size+1] # Extract up to the chunk size
|
134 |
|
135 |
# Store the new examples
|
136 |
all_generated_examples.extend(generated_examples)
|
|
|
143 |
|
144 |
# Display all generated examples
|
145 |
for idx, example in enumerate(all_generated_examples):
|
146 |
+
st.write(f"Example {idx+1}: {example.strip()}")
|
147 |
|
148 |
# Update session state to prevent repetition of old prompts
|
149 |
st.session_state.messages = [] # Clear messages after each generation
|