Mustafa Başar commited on
Commit
d11acd4
·
verified ·
1 Parent(s): e5653cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -10
app.py CHANGED
@@ -42,6 +42,61 @@ scenarios = [
42
  }
43
  ]
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  # Simulated user progress
46
  user_progress = {
47
  "completed_scenarios": 0,
@@ -65,7 +120,11 @@ prompt_tips = [
65
  "Specify how to handle edge cases like missing values or outliers",
66
  "Include context about the data structure and your goal",
67
  "Break complex tasks into numbered steps",
68
- "Use clear, concise language rather than vague instructions"
 
 
 
 
69
  ]
70
 
71
  # Simulate AI evaluation of prompts
@@ -127,9 +186,17 @@ def evaluate_prompt(user_prompt, scenario):
127
  "feedback": feedback
128
  }
129
 
130
- # Generate a new scenario
131
- def get_new_scenario():
132
- scenario = random.choice(scenarios)
 
 
 
 
 
 
 
 
133
  return (
134
  scenario["title"],
135
  scenario["description"],
@@ -138,10 +205,24 @@ def get_new_scenario():
138
  scenario["sample_data"]
139
  )
140
 
 
 
 
 
141
  # Evaluate user input and provide feedback
142
  def submit_prompt(prompt, title, description, level, category):
143
- # Find the scenario
144
- scenario = next((s for s in scenarios if s["title"] == title), scenarios[0])
 
 
 
 
 
 
 
 
 
 
145
 
146
  # Evaluate prompt
147
  evaluation = evaluate_prompt(prompt, scenario)
@@ -191,7 +272,8 @@ def display_leaderboard():
191
 
192
  # Display random tip
193
  def get_random_tip():
194
- return random.choice(prompt_tips)
 
195
 
196
  # Build Gradio interface
197
  with gr.Blocks(theme=gr.themes.Soft(), title="PromptMaster for Data Analytics") as app:
@@ -210,9 +292,8 @@ with gr.Blocks(theme=gr.themes.Soft(), title="PromptMaster for Data Analytics")
210
  gr.Markdown("### Sample Data")
211
  sample_data_output = gr.HTML()
212
 
213
- # Prompt tip
214
- with gr.Accordion("Tip for Effective Prompting", open=False):
215
- tip_output = gr.Markdown()
216
 
217
  # User input
218
  prompt_input = gr.Textbox(label="Your Prompt", lines=5, placeholder="Write your prompt here...")
@@ -221,6 +302,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="PromptMaster for Data Analytics")
221
  with gr.Row():
222
  submit_btn = gr.Button("Submit Prompt", variant="primary")
223
  new_scenario_btn = gr.Button("Get New Scenario")
 
224
  new_tip_btn = gr.Button("Get Prompt Tip")
225
 
226
  # Results
@@ -232,6 +314,11 @@ with gr.Blocks(theme=gr.themes.Soft(), title="PromptMaster for Data Analytics")
232
  outputs=[title_output, description_output, level_output, category_output, sample_data_output]
233
  )
234
 
 
 
 
 
 
235
  new_tip_btn.click(
236
  get_random_tip,
237
  outputs=[tip_output]
 
42
  }
43
  ]
44
 
45
+ # AI-generated scenarios templates
46
+ ai_scenario_templates = [
47
+ {
48
+ "title_prefix": "Data Analysis with ",
49
+ "tools": ["Power BI", "Tableau", "Excel", "Python", "R", "SQL"],
50
+ "data_types": ["sales", "customer", "financial", "survey", "marketing", "operational"],
51
+ "problems": ["missing values", "outliers", "inconsistent formats", "duplicates", "aggregation needs"],
52
+ "level_options": ["Beginner", "Intermediate", "Advanced"]
53
+ },
54
+ {
55
+ "title_prefix": "Visualization in ",
56
+ "tools": ["Power BI", "Tableau", "Matplotlib", "Seaborn", "D3.js", "Excel"],
57
+ "data_types": ["time series", "categorical", "geospatial", "hierarchical", "correlation", "comparison"],
58
+ "problems": ["finding the right chart type", "color selection", "handling scale issues", "showing too many variables", "highlighting key insights"],
59
+ "level_options": ["Beginner", "Intermediate", "Advanced"]
60
+ },
61
+ {
62
+ "title_prefix": "Query Optimization for ",
63
+ "tools": ["SQL Server", "PostgreSQL", "MySQL", "BigQuery", "Snowflake", "DynamoDB"],
64
+ "data_types": ["relational", "document", "key-value", "graph", "time series", "data warehouse"],
65
+ "problems": ["slow joins", "inefficient filters", "missing indexes", "poor aggregation", "subquery complexity"],
66
+ "level_options": ["Beginner", "Intermediate", "Advanced"]
67
+ }
68
+ ]
69
+
70
+ # Generate an AI scenario
71
+ def generate_ai_scenario():
72
+ template = random.choice(ai_scenario_templates)
73
+
74
+ tool = random.choice(template["tools"])
75
+ data_type = random.choice(template["data_types"])
76
+ problem = random.choice(template["problems"])
77
+ level = random.choice(template["level_options"])
78
+
79
+ title = f"{template['title_prefix']}{tool}"
80
+
81
+ description = f"You're working with {data_type} data and encountering issues with {problem}. " + \
82
+ f"How would you instruct an AI assistant to help you solve this problem using {tool}?"
83
+
84
+ ideal_prompt = f"Help me address {problem} in my {data_type} data using {tool}. " + \
85
+ f"Please provide a step-by-step approach, including how to identify the issue, " + \
86
+ f"resolve it efficiently, and verify the solution is working."
87
+
88
+ # Use the sales data as a generic example
89
+ sample_data = sample_sales_data.head(10).to_html() if random.random() > 0.5 else f"<pre>{sample_sql_query}</pre>"
90
+
91
+ return {
92
+ "title": title,
93
+ "description": description,
94
+ "level": level,
95
+ "category": tool,
96
+ "ideal_prompt": ideal_prompt,
97
+ "sample_data": sample_data
98
+ }
99
+
100
  # Simulated user progress
101
  user_progress = {
102
  "completed_scenarios": 0,
 
120
  "Specify how to handle edge cases like missing values or outliers",
121
  "Include context about the data structure and your goal",
122
  "Break complex tasks into numbered steps",
123
+ "Use clear, concise language rather than vague instructions",
124
+ "Provide examples when possible to clarify your expectations",
125
+ "Request explanations when solutions are complex",
126
+ "Ask for alternatives to compare different approaches",
127
+ "Define success criteria so the AI knows what a good result looks like"
128
  ]
129
 
130
  # Simulate AI evaluation of prompts
 
186
  "feedback": feedback
187
  }
188
 
189
+ # Generate a new scenario (mix of predefined and AI-generated)
190
+ def get_new_scenario(use_ai_generated=None):
191
+ # 50% chance to get an AI-generated scenario if not specified
192
+ if use_ai_generated is None:
193
+ use_ai_generated = random.random() > 0.5
194
+
195
+ if use_ai_generated:
196
+ scenario = generate_ai_scenario()
197
+ else:
198
+ scenario = random.choice(scenarios)
199
+
200
  return (
201
  scenario["title"],
202
  scenario["description"],
 
205
  scenario["sample_data"]
206
  )
207
 
208
+ # Specifically get an AI-generated scenario
209
+ def get_ai_scenario():
210
+ return get_new_scenario(use_ai_generated=True)
211
+
212
  # Evaluate user input and provide feedback
213
  def submit_prompt(prompt, title, description, level, category):
214
+ # First try to find in predefined scenarios
215
+ scenario = next((s for s in scenarios if s["title"] == title), None)
216
+
217
+ # If not found, create a temporary scenario object from inputs
218
+ if scenario is None:
219
+ scenario = {
220
+ "title": title,
221
+ "description": description,
222
+ "level": level,
223
+ "category": category,
224
+ "ideal_prompt": description # Use description as a fallback for keywords
225
+ }
226
 
227
  # Evaluate prompt
228
  evaluation = evaluate_prompt(prompt, scenario)
 
272
 
273
  # Display random tip
274
  def get_random_tip():
275
+ tip = random.choice(prompt_tips)
276
+ return f"**Tip:** {tip}"
277
 
278
  # Build Gradio interface
279
  with gr.Blocks(theme=gr.themes.Soft(), title="PromptMaster for Data Analytics") as app:
 
292
  gr.Markdown("### Sample Data")
293
  sample_data_output = gr.HTML()
294
 
295
+ # Prompt tip box - NOW VISIBLE BY DEFAULT
296
+ tip_output = gr.Markdown(label="Prompt Tip")
 
297
 
298
  # User input
299
  prompt_input = gr.Textbox(label="Your Prompt", lines=5, placeholder="Write your prompt here...")
 
302
  with gr.Row():
303
  submit_btn = gr.Button("Submit Prompt", variant="primary")
304
  new_scenario_btn = gr.Button("Get New Scenario")
305
+ ai_scenario_btn = gr.Button("Generate AI Scenario")
306
  new_tip_btn = gr.Button("Get Prompt Tip")
307
 
308
  # Results
 
314
  outputs=[title_output, description_output, level_output, category_output, sample_data_output]
315
  )
316
 
317
+ ai_scenario_btn.click(
318
+ get_ai_scenario,
319
+ outputs=[title_output, description_output, level_output, category_output, sample_data_output]
320
+ )
321
+
322
  new_tip_btn.click(
323
  get_random_tip,
324
  outputs=[tip_output]