anktechsol commited on
Commit
f4ff497
Β·
verified Β·
1 Parent(s): a216fe9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +266 -0
app.py ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def recommend_model(modality,
4
+ outputs,
5
+ domains,
6
+ regulated,
7
+ data_sensitivity,
8
+ volume,
9
+ latency,
10
+ context_size,
11
+ customization):
12
+ # Normalize inputs
13
+ modality = modality or []
14
+ outputs = outputs or []
15
+ domains = domains or []
16
+ regulated = regulated or []
17
+ customization = customization or []
18
+
19
+ notes = []
20
+
21
+ # --- Step 1: Model TYPE recommendation ---
22
+ model_type = []
23
+ deployment = []
24
+ extra = []
25
+
26
+ # Modality β†’ type
27
+ if "Text in β†’ text out" in modality:
28
+ model_type.append("Text-only LLM (chat/completions)")
29
+ if "Images in (docs, UI, scans…)" in modality:
30
+ model_type.append("Vision-Language Model (VLM)")
31
+ if "Audio in (speech)" in modality:
32
+ model_type.append("ASR model (speech-to-text) + LLM")
33
+ if "Structured data (tables, logs…)" in modality:
34
+ model_type.append("Tabular ML model or LLM+tools")
35
+ if "Code" in modality:
36
+ model_type.append("Code-specialized LLM")
37
+
38
+ if not model_type:
39
+ model_type.append("Start with a general-purpose LLM and refine after a quick eval")
40
+
41
+ # Domains & regulation
42
+ if "Healthcare" in domains or "Finance" in domains or "Legal" in domains:
43
+ notes.append("You have a regulated or high-stakes domain β†’ prioritize control, audits, and deterministic behavior.")
44
+ if "Yes – regulated (PII/PHI/financial/legal)" in regulated:
45
+ notes.append("Regulated data flagged β†’ prefer VPC / on-prem deployment and strong data governance.")
46
+ deployment.append("Self-hosted or VPC deployment (open-source or private endpoints)")
47
+
48
+ # If no specific deployment yet
49
+ if not deployment:
50
+ if volume in ["1,000 – 100,000 per day", "100,000+ per day"]:
51
+ deployment.append("Cost-optimized open-source model on your infra")
52
+ else:
53
+ deployment.append("Managed API (hosted LLM) for faster go-to-market")
54
+
55
+ # Latency
56
+ if latency == "< 500 ms":
57
+ notes.append("You selected tight latency β†’ smaller models or distilled variants are preferable.")
58
+ elif latency == "0.5 – 5 s":
59
+ notes.append("Interactive latency acceptable β†’ medium-sized models are fine.")
60
+ else:
61
+ notes.append("Batch latency acceptable β†’ you can afford heavier models if they improve quality.")
62
+
63
+ # Context window
64
+ if context_size == "< 4K tokens":
65
+ notes.append("Small context β†’ standard context models are sufficient.")
66
+ elif context_size == "4K – 32K tokens":
67
+ notes.append("Medium context β†’ choose models with extended context support.")
68
+ else:
69
+ notes.append("Large context β†’ combine long-context models with a RAG (retrieval) layer.")
70
+
71
+ # Customization
72
+ if "Prompt only is enough" in customization:
73
+ extra.append("Phase 1: Start with strong prompting and guardrails, no fine-tuning.")
74
+ if "Need consistent style/domain language (fine-tune)" in customization:
75
+ extra.append("Consider fine-tuning an open-source base model on your domain data.")
76
+ if "Complex workflows or internal ontology (RAG + tools + optional fine-tune)" in customization:
77
+ extra.append("Design a RAG + tools architecture; then fine-tune if you need more consistency.")
78
+
79
+ # Build textual recommendation
80
+ type_text = "- " + "\
81
+ - ".join(model_type)
82
+ deploy_text = "- " + "\
83
+ - ".join(deployment)
84
+ notes_text = "- " + "\
85
+ - ".join(notes) if notes else "No special constraints detected."
86
+ extra_text = "- " + "\
87
+ - ".join(extra) if extra else "You can start without fine-tuning; revisit after initial usage data."
88
+
89
+ # AnkTechsol lead magnet CTA
90
+ cta = (
91
+ "Next step with AnkTechsol:\
92
+ "
93
+ "- We can run a 1-week 'Model Bake-Off' on your real data across 3–5 shortlisted models.\
94
+ "
95
+ "- You get a clear winner with accuracy, latency, and cost metrics plus a deployment plan into your cloud.\
96
+ "
97
+ "- Book a free 30-minute Model Strategy Call at anktechsol.com."
98
+ )
99
+
100
+ summary = (
101
+ "### Recommended model types:\
102
+ "
103
+ f"{type_text}\
104
+ \
105
+ "
106
+ "### Recommended deployment approach:\
107
+ "
108
+ f"{deploy_text}\
109
+ \
110
+ "
111
+ "### Constraints & design notes:\
112
+ "
113
+ f"{notes_text}\
114
+ \
115
+ "
116
+ "### Customization guidance:\
117
+ "
118
+ f"{extra_text}\
119
+ \
120
+ "
121
+ "### How AnkTechsol can help:\
122
+ "
123
+ f"{cta}"
124
+ )
125
+
126
+ return summary
127
+
128
+
129
+ with gr.Blocks(title="AI Model Selection Checklist – AnkTechsol") as demo:
130
+ gr.Markdown(
131
+ \"\"\"
132
+ # AI Model Selection Checklist
133
+ Quickly decide which AI model type to use for your product.
134
+
135
+ Fill the checklist below and get a tailored recommendation.
136
+ \"\"\"
137
+ )
138
+
139
+ with gr.Row():
140
+ with gr.Column():
141
+ gr.Markdown("### 1. Task & Modality")
142
+
143
+ modality = gr.CheckboxGroup(
144
+ label="What are your inputs?",
145
+ choices=[
146
+ "Text in β†’ text out",
147
+ "Images in (docs, UI, scans…)",
148
+ "Audio in (speech)",
149
+ "Structured data (tables, logs…)",
150
+ "Code",
151
+ ],
152
+ )
153
+
154
+ outputs = gr.CheckboxGroup(
155
+ label="What kind of output do you need?",
156
+ choices=[
157
+ "Natural language answer / summary",
158
+ "Classification / tagging",
159
+ "Field extraction from text/PDF",
160
+ "Content generation (marketing, UX copy)",
161
+ "Scoring / ranking / decision",
162
+ ],
163
+ )
164
+
165
+ domains = gr.CheckboxGroup(
166
+ label="Domain",
167
+ choices=[
168
+ "General / consumer",
169
+ "Ecommerce / SaaS",
170
+ "Finance",
171
+ "Healthcare",
172
+ "Legal",
173
+ "Internal company knowledge",
174
+ ],
175
+ )
176
+
177
+ regulated = gr.CheckboxGroup(
178
+ label="Regulated / sensitive?",
179
+ choices=[
180
+ "Yes – regulated (PII/PHI/financial/legal)",
181
+ "No – mostly non-sensitive",
182
+ ],
183
+ )
184
+
185
+ with gr.Column():
186
+ gr.Markdown("### 2. Constraints")
187
+
188
+ data_sensitivity = gr.Radio(
189
+ label="Data residency / governance",
190
+ choices=[
191
+ "Can use standard SaaS APIs",
192
+ "Must stay in specific cloud/region",
193
+ "Strict: prefer on-prem / VPC only",
194
+ ],
195
+ value="Can use standard SaaS APIs",
196
+ )
197
+
198
+ volume = gr.Radio(
199
+ label="Expected volume (per day)",
200
+ choices=[
201
+ "< 1,000 per day",
202
+ "1,000 – 100,000 per day",
203
+ "100,000+ per day",
204
+ ],
205
+ value="< 1,000 per day",
206
+ )
207
+
208
+ latency = gr.Radio(
209
+ label="Latency tolerance",
210
+ choices=[
211
+ "< 500 ms",
212
+ "0.5 – 5 s",
213
+ "> 5 s is acceptable",
214
+ ],
215
+ value="0.5 – 5 s",
216
+ )
217
+
218
+ context_size = gr.Radio(
219
+ label="Max context size you need at once",
220
+ choices=[
221
+ "< 4K tokens",
222
+ "4K – 32K tokens",
223
+ "32K – 200K tokens",
224
+ ],
225
+ value="4K – 32K tokens",
226
+ )
227
+
228
+ customization = gr.CheckboxGroup(
229
+ label="Customization level",
230
+ choices=[
231
+ "Prompt only is enough",
232
+ "Need consistent style/domain language (fine-tune)",
233
+ "Complex workflows or internal ontology (RAG + tools + optional fine-tune)",
234
+ ],
235
+ )
236
+
237
+ run_button = gr.Button("Generate Recommendation", variant="primary")
238
+ output = gr.Markdown(label="Recommendation")
239
+
240
+ run_button.click(
241
+ fn=recommend_model,
242
+ inputs=[
243
+ modality,
244
+ outputs,
245
+ domains,
246
+ regulated,
247
+ data_sensitivity,
248
+ volume,
249
+ latency,
250
+ context_size,
251
+ customization,
252
+ ],
253
+ outputs=output,
254
+ )
255
+
256
+ gr.Markdown(
257
+ \"\"\"
258
+ ---
259
+
260
+ Made by **AnkTechsol**
261
+ Need help implementing this? Visit anktechsol.com to talk to our team.
262
+ \"\"\"
263
+ )
264
+
265
+ if __name__ == "__main__":
266
+ demo.launch()