DJHumanRPT commited on
Commit
7f4683b
·
verified ·
1 Parent(s): e44cf0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +298 -2
app.py CHANGED
@@ -43,6 +43,251 @@ def get_or_create_document_converter():
43
  return converter
44
 
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  @st.cache_data
47
  def parse_documents(uploaded_files):
48
  """Parse multiple document files and extract their text content."""
@@ -1151,6 +1396,56 @@ with tab1:
1151
  index=0,
1152
  )
1153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1154
  if setup_option == "Upload existing template":
1155
  st.subheader("Upload Template File")
1156
  uploaded_template = st.file_uploader(
@@ -1284,6 +1579,7 @@ with tab1:
1284
  with tab2:
1285
  if st.session_state.show_template_editor and st.session_state.template_spec:
1286
  st.header("Template Editor")
 
1287
 
1288
  # Initialize session state variables
1289
  if "suggested_variables" not in st.session_state:
@@ -1309,7 +1605,7 @@ with tab2:
1309
  # LEFT COLUMN - Settings
1310
  with left_col:
1311
  # Basic template information
1312
- with st.expander("Template Information", expanded=True):
1313
  col1, col2 = st.columns(2)
1314
  with col1:
1315
  st.session_state.template_spec["name"] = st.text_input(
@@ -1327,7 +1623,7 @@ with tab2:
1327
  )
1328
 
1329
  # Prompt Template Section
1330
- with st.expander("Prompt Template", expanded=False):
1331
  st.info(
1332
  "Use {variable_name} to refer to input variables in your template"
1333
  )
 
43
  return converter
44
 
45
 
46
+ def create_example_templates():
47
+ examples = [
48
+ {
49
+ "name": "Character Generator",
50
+ "description": "Generate fantasy character descriptions based on selected traits",
51
+ "version": "1.0.0",
52
+ "input": [
53
+ {
54
+ "name": "race",
55
+ "description": "Character's fantasy race",
56
+ "type": "categorical",
57
+ "options": ["Human", "Elf", "Dwarf", "Orc", "Halfling"],
58
+ "min": 1,
59
+ "max": 1,
60
+ },
61
+ {
62
+ "name": "class",
63
+ "description": "Character's profession or class",
64
+ "type": "categorical",
65
+ "options": ["Warrior", "Mage", "Rogue", "Cleric", "Ranger"],
66
+ "min": 1,
67
+ "max": 1,
68
+ },
69
+ {
70
+ "name": "alignment",
71
+ "description": "Character's moral alignment",
72
+ "type": "categorical",
73
+ "options": [
74
+ "Lawful Good",
75
+ "Neutral",
76
+ "Chaotic Evil",
77
+ "Lawful Evil",
78
+ "Chaotic Good",
79
+ ],
80
+ "min": 1,
81
+ "max": 1,
82
+ },
83
+ ],
84
+ "output": [
85
+ {
86
+ "name": "character_name",
87
+ "description": "Generated character name",
88
+ "type": "string",
89
+ "min": 3,
90
+ "max": 30,
91
+ },
92
+ {
93
+ "name": "background",
94
+ "description": "Character background story",
95
+ "type": "string",
96
+ "min": 100,
97
+ "max": 500,
98
+ },
99
+ ],
100
+ "prompt": "Create a fantasy character with the following traits:\nRace: {race}\nClass: {class}\nAlignment: {alignment}\n\nGenerate a suitable name and background story for this character.",
101
+ },
102
+ {
103
+ "name": "Recipe Generator",
104
+ "description": "Generate cooking recipes based on ingredients and cuisine",
105
+ "version": "1.0.0",
106
+ "input": [
107
+ {
108
+ "name": "cuisine",
109
+ "description": "Style of cooking",
110
+ "type": "categorical",
111
+ "options": ["Italian", "Mexican", "Chinese", "Indian", "French"],
112
+ "min": 1,
113
+ "max": 1,
114
+ },
115
+ {
116
+ "name": "main_ingredient",
117
+ "description": "Primary ingredient",
118
+ "type": "categorical",
119
+ "options": ["Chicken", "Beef", "Fish", "Tofu", "Vegetables"],
120
+ "min": 1,
121
+ "max": 1,
122
+ },
123
+ {
124
+ "name": "dietary_restriction",
125
+ "description": "Dietary requirements",
126
+ "type": "categorical",
127
+ "options": [
128
+ "None",
129
+ "Vegetarian",
130
+ "Vegan",
131
+ "Gluten-free",
132
+ "Dairy-free",
133
+ ],
134
+ "min": 1,
135
+ "max": 1,
136
+ },
137
+ ],
138
+ "output": [
139
+ {
140
+ "name": "recipe_name",
141
+ "description": "Name of the recipe",
142
+ "type": "string",
143
+ "min": 5,
144
+ "max": 50,
145
+ },
146
+ {
147
+ "name": "ingredients",
148
+ "description": "List of ingredients needed",
149
+ "type": "string",
150
+ "min": 50,
151
+ "max": 300,
152
+ },
153
+ {
154
+ "name": "instructions",
155
+ "description": "Cooking instructions",
156
+ "type": "string",
157
+ "min": 100,
158
+ "max": 500,
159
+ },
160
+ ],
161
+ "prompt": "Create a {cuisine} recipe using {main_ingredient} as the main ingredient. The recipe should be {dietary_restriction}.\n\nProvide a recipe name, list of ingredients, and cooking instructions.",
162
+ },
163
+ {
164
+ "name": "Product Description",
165
+ "description": "Generate marketing descriptions for products",
166
+ "version": "1.0.0",
167
+ "input": [
168
+ {
169
+ "name": "product_type",
170
+ "description": "Type of product",
171
+ "type": "categorical",
172
+ "options": [
173
+ "Smartphone",
174
+ "Laptop",
175
+ "Headphones",
176
+ "Smartwatch",
177
+ "Camera",
178
+ ],
179
+ "min": 1,
180
+ "max": 1,
181
+ },
182
+ {
183
+ "name": "target_audience",
184
+ "description": "Target customer demographic",
185
+ "type": "categorical",
186
+ "options": [
187
+ "Students",
188
+ "Professionals",
189
+ "Gamers",
190
+ "Creatives",
191
+ "Seniors",
192
+ ],
193
+ "min": 1,
194
+ "max": 1,
195
+ },
196
+ {
197
+ "name": "price_tier",
198
+ "description": "Price category",
199
+ "type": "categorical",
200
+ "options": [
201
+ "Budget",
202
+ "Mid-range",
203
+ "Premium",
204
+ "Luxury",
205
+ "Enterprise",
206
+ ],
207
+ "min": 1,
208
+ "max": 1,
209
+ },
210
+ ],
211
+ "output": [
212
+ {
213
+ "name": "product_name",
214
+ "description": "Generated product name",
215
+ "type": "string",
216
+ "min": 5,
217
+ "max": 30,
218
+ },
219
+ {
220
+ "name": "tagline",
221
+ "description": "Short marketing tagline",
222
+ "type": "string",
223
+ "min": 10,
224
+ "max": 100,
225
+ },
226
+ {
227
+ "name": "description",
228
+ "description": "Full product description",
229
+ "type": "string",
230
+ "min": 100,
231
+ "max": 500,
232
+ },
233
+ ],
234
+ "prompt": "Create a marketing description for a {price_tier} {product_type} targeted at {target_audience}.\n\nProvide a product name, catchy tagline, and compelling product description.",
235
+ },
236
+ ]
237
+
238
+ return examples
239
+
240
+
241
+ # Create a function to display example outputs
242
+ def create_example_outputs(template):
243
+ # Predefined outputs for each template
244
+ if template["name"] == "Character Generator":
245
+ outputs = {
246
+ "Human Warrior Lawful Good": {
247
+ "character_name": "Sir Galahad Ironheart",
248
+ "background": "Born to a noble family in the kingdom of Valorhaven, Sir Galahad trained from childhood in the arts of combat. After saving the king's daughter from bandits, he was knighted and now serves as captain of the royal guard. His unwavering dedication to justice and honor has made him a legend throughout the realm, though his strict adherence to the code of chivalry sometimes puts him at odds with more pragmatic allies.",
249
+ },
250
+ "Elf Mage Chaotic Good": {
251
+ "character_name": "Lyraniel Starweaver",
252
+ "background": "Raised in the ancient forest of Eldrath, Lyraniel discovered her affinity for arcane magic when she accidentally set a tree ablaze during an argument. Rather than follow the structured magical traditions of her people, she left to study diverse magical practices across the continent. She now uses her considerable powers to protect the innocent and fight tyranny, though her methods are often unpredictable and sometimes cause as much chaos as they resolve.",
253
+ },
254
+ "Dwarf Rogue Neutral": {
255
+ "character_name": "Grimble Lockpick",
256
+ "background": "Once a respected jeweler in the mountain halls of Karak-Dûm, Grimble's curiosity about the perfect lock led him down a different path. Neither malicious nor heroic, he sees himself as a professional who offers specialized services for the right price. His reputation for being able to open any lock or disarm any trap has made him sought after by adventurers and nobles alike, though he remains careful to avoid political entanglements that might limit his freedom.",
257
+ },
258
+ }
259
+ elif template["name"] == "Recipe Generator":
260
+ outputs = {
261
+ "Italian Chicken None": {
262
+ "recipe_name": "Tuscan Herb-Roasted Chicken",
263
+ "ingredients": "- 4 chicken breasts\n- 3 tbsp olive oil\n- 4 cloves garlic, minced\n- 1 tbsp fresh rosemary, chopped\n- 1 tbsp fresh thyme, chopped\n- 1 lemon, zested and juiced\n- 1 cup cherry tomatoes, halved\n- 1/2 cup chicken broth\n- 1/4 cup dry white wine\n- Salt and pepper to taste\n- Fresh basil for garnish",
264
+ "instructions": "1. Preheat oven to 375°F (190°C).\n2. Season chicken breasts with salt and pepper.\n3. In a large oven-safe skillet, heat olive oil over medium-high heat.\n4. Sear chicken breasts for 3-4 minutes per side until golden brown.\n5. Add garlic, rosemary, and thyme to the pan and cook for 1 minute until fragrant.\n6. Add lemon zest, lemon juice, cherry tomatoes, chicken broth, and white wine.\n7. Transfer skillet to the oven and roast for 20-25 minutes until chicken is cooked through.\n8. Garnish with fresh basil before serving.",
265
+ },
266
+ "Mexican Vegetables Vegetarian": {
267
+ "recipe_name": "Roasted Vegetable Enchiladas Verde",
268
+ "ingredients": "- 2 zucchini, diced\n- 1 red bell pepper, diced\n- 1 yellow bell pepper, diced\n- 1 red onion, sliced\n- 2 cups mushrooms, sliced\n- 3 tbsp olive oil\n- 2 tsp cumin\n- 1 tsp chili powder\n- 1 tsp oregano\n- 8 corn tortillas\n- 2 cups salsa verde\n- 1 1/2 cups shredded Monterey Jack cheese\n- 1 avocado, sliced\n- 1/4 cup cilantro, chopped\n- Lime wedges for serving",
269
+ "instructions": "1. Preheat oven to 425°F (220°C).\n2. Toss zucchini, bell peppers, onion, and mushrooms with olive oil, cumin, chili powder, oregano, salt, and pepper.\n3. Spread vegetables on a baking sheet and roast for 20 minutes, stirring halfway through.\n4. Reduce oven temperature to 375°F (190°C).\n5. Warm tortillas slightly to make them pliable.\n6. Fill each tortilla with roasted vegetables and roll up.\n7. Place enchiladas seam-side down in a baking dish.\n8. Pour salsa verde over enchiladas and sprinkle with cheese.\n9. Bake for 20-25 minutes until cheese is melted and bubbly.\n10. Garnish with avocado slices and cilantro. Serve with lime wedges.",
270
+ },
271
+ }
272
+ elif template["name"] == "Product Description":
273
+ outputs = {
274
+ "Smartphone Professionals Premium": {
275
+ "product_name": "ExecuTech Pro X9",
276
+ "tagline": "Seamless productivity meets uncompromising elegance.",
277
+ "description": 'The ExecuTech Pro X9 redefines what a business smartphone can be. Crafted with aerospace-grade materials and featuring our revolutionary 6.7" CrystalClear AMOLED display, the Pro X9 ensures your presentations and video conferences look impeccable in any lighting condition. The advanced 5-lens camera system with AI enhancement captures professional-quality images for your reports and social media, while the dedicated security co-processor keeps your sensitive data protected with military-grade encryption. With an impressive 36-hour battery life and our proprietary RapidCharge technology, the Pro X9 keeps pace with your demanding schedule. Experience the perfect balance of performance and sophistication that successful professionals deserve.',
278
+ },
279
+ "Headphones Gamers Mid-range": {
280
+ "product_name": "SonicStrike GT-500",
281
+ "tagline": "Hear every move. Dominate every game.",
282
+ "description": "Level up your gaming experience with the SonicStrike GT-500 gaming headset. Engineered specifically for competitive gamers, these headphones feature our proprietary 50mm UltraBass drivers that deliver thunderous lows while maintaining crystal-clear highs, allowing you to hear enemy footsteps with pinpoint accuracy. The detachable boom microphone with noise-cancellation ensures your teammates hear your callouts clearly, even in the heat of battle. With memory foam ear cushions wrapped in breathable mesh fabric, the GT-500 remains comfortable during marathon gaming sessions. Compatible with all major gaming platforms and featuring customizable RGB lighting through our GameSync app, the SonicStrike GT-500 offers premium features at a price that won't break the bank. Your gaming advantage starts here.",
283
+ },
284
+ }
285
+ else:
286
+ outputs = {}
287
+
288
+ return outputs
289
+
290
+
291
  @st.cache_data
292
  def parse_documents(uploaded_files):
293
  """Parse multiple document files and extract their text content."""
 
1396
  index=0,
1397
  )
1398
 
1399
+ if (
1400
+ setup_option == "Create new template from documents"
1401
+ or setup_option == "Create an empty template"
1402
+ ):
1403
+ # Add Examples section
1404
+ st.markdown("---")
1405
+ st.subheader("Or try one of our examples")
1406
+
1407
+ # Get example templates
1408
+ example_templates = create_example_templates()
1409
+
1410
+ # Create columns for example cards
1411
+ cols = st.columns(len(example_templates))
1412
+
1413
+ # Display each example in a card
1414
+ for i, (col, template) in enumerate(zip(cols, example_templates)):
1415
+ with col:
1416
+ st.markdown(f"#### {template['name']}")
1417
+ st.markdown(f"*{template['description']}*")
1418
+
1419
+ # Show input variables
1420
+ with st.expander("Inputs and Outputs", expanded=False):
1421
+ st.markdown("**Inputs:**")
1422
+ for inp in template["input"]:
1423
+ st.markdown(f"- {inp['name']}: {inp['type']}")
1424
+
1425
+ # Show output variables
1426
+ st.markdown("**Outputs:**")
1427
+ for out in template["output"]:
1428
+ st.markdown(f"- {out['name']}: {out['type']}")
1429
+
1430
+ # Button to use this example
1431
+ if st.button(f"Use this example", key=f"use_example_{i}"):
1432
+ st.session_state.template_spec = template
1433
+ st.session_state.show_template_editor = True
1434
+
1435
+ # Create some example outputs to show
1436
+ example_outputs = create_example_outputs(template)
1437
+
1438
+ # Store example outputs in session state
1439
+ st.session_state.example_outputs = example_outputs
1440
+
1441
+ # Success message
1442
+ st.success(
1443
+ f"Example template loaded! Go to the 'Edit Template' tab to see it in action."
1444
+ )
1445
+
1446
+ # Rerun to update the UI
1447
+ st.rerun()
1448
+
1449
  if setup_option == "Upload existing template":
1450
  st.subheader("Upload Template File")
1451
  uploaded_template = st.file_uploader(
 
1579
  with tab2:
1580
  if st.session_state.show_template_editor and st.session_state.template_spec:
1581
  st.header("Template Editor")
1582
+ st.subheader(st.session_state.template_spec["name"])
1583
 
1584
  # Initialize session state variables
1585
  if "suggested_variables" not in st.session_state:
 
1605
  # LEFT COLUMN - Settings
1606
  with left_col:
1607
  # Basic template information
1608
+ with st.expander("Template Information (Metadata)", expanded=False):
1609
  col1, col2 = st.columns(2)
1610
  with col1:
1611
  st.session_state.template_spec["name"] = st.text_input(
 
1623
  )
1624
 
1625
  # Prompt Template Section
1626
+ with st.expander("Prompt Template", expanded=True):
1627
  st.info(
1628
  "Use {variable_name} to refer to input variables in your template"
1629
  )