anktechsol commited on
Commit
0488a88
·
verified ·
1 Parent(s): f0bcf12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -175
app.py CHANGED
@@ -1,175 +1 @@
1
- import gradio as gr
2
- import requests
3
-
4
- NL = chr(10)
5
-
6
- # Map user-facing modality choices to HF Hub task tags
7
- TASK_MAP = {
8
- "Text in -> text out": ["text-generation", "text2text-generation"],
9
- "Images in (docs, UI, scans)": ["image-to-text", "visual-question-answering"],
10
- "Audio in (speech)": ["automatic-speech-recognition"],
11
- "Structured data (tables, logs)": ["tabular-classification", "tabular-regression"],
12
- "Code": ["text-generation"],
13
- }
14
-
15
- LICENSE_FILTER = {
16
- "Standard SaaS API is fine": None,
17
- "Must stay in a specific cloud region": None,
18
- "Strict: prefer on-prem / VPC only": "apache-2.0",
19
- }
20
-
21
- def fetch_top_models(tasks, license_filter=None, top_n=5):
22
- seen = set()
23
- results = []
24
- for task in tasks:
25
- try:
26
- params = {
27
- "pipeline_tag": task,
28
- "sort": "downloads",
29
- "direction": "-1",
30
- "limit": "20",
31
- }
32
- if license_filter:
33
- params["license"] = license_filter
34
- resp = requests.get(
35
- "https://huggingface.co/api/models",
36
- params=params,
37
- timeout=15,
38
- )
39
- if resp.status_code == 200:
40
- data = resp.json()
41
- for m in data:
42
- mid = m.get("modelId", m.get("id", ""))
43
- if mid and mid not in seen:
44
- seen.add(mid)
45
- downloads = m.get("downloads", 0) or 0
46
- likes = m.get("likes", 0) or 0
47
- results.append((mid, task, downloads, likes))
48
- if len(results) >= top_n * len(tasks):
49
- break
50
- except Exception:
51
- pass
52
- results.sort(key=lambda x: x[2], reverse=True)
53
- return results[:top_n]
54
-
55
- def format_model_table(models):
56
- if not models:
57
- return "No models found via HF API. Please try again."
58
- header = "| # | Model | Task | Downloads | Likes |" + NL
59
- header += "|---|-------|------|-----------|-------|" + NL
60
- rows = ""
61
- for i, (mid, task, dl, lk) in enumerate(models, 1):
62
- dl_fmt = f"{dl:,}" if dl else "N/A"
63
- lk_fmt = f"{lk:,}" if lk else "N/A"
64
- rows += f"| {i} | [{mid}](https://huggingface.co/{mid}) | `{task}` | {dl_fmt} | {lk_fmt} |" + NL
65
- return header + rows
66
-
67
- def recommend_model(
68
- modality, outputs, domains, regulated,
69
- data_sensitivity, volume, latency,
70
- context_size, customization
71
- ):
72
- # Collect HF tasks to query
73
- hf_tasks = []
74
- for m in modality:
75
- hf_tasks.extend(TASK_MAP.get(m, []))
76
- # Deduplicate, keep order
77
- seen_t = set()
78
- unique_tasks = []
79
- for t in hf_tasks:
80
- if t not in seen_t:
81
- seen_t.add(t)
82
- unique_tasks.append(t)
83
- if not unique_tasks:
84
- unique_tasks = ["text-generation"]
85
-
86
- license_filter = LICENSE_FILTER.get(data_sensitivity)
87
-
88
- # Fetch live models
89
- live_models = fetch_top_models(unique_tasks, license_filter=license_filter, top_n=5)
90
- model_table = format_model_table(live_models)
91
-
92
- # Deployment path
93
- if data_sensitivity == "Strict: prefer on-prem / VPC only":
94
- deploy_path = "🚀 **Private Self-Hosted** - Run top open-source models above via Ollama or vLLM on your own infra."
95
- elif volume == "100,000+":
96
- deploy_path = "💰 **Cost-Optimized Scale** - Use provisioned throughput for closed models, or self-host on GPU clusters."
97
- else:
98
- deploy_path = "⚡ **Serverless API** - Closed models: OpenAI/Anthropic/Google APIs. Open-source: HF Inference Endpoints."
99
-
100
- # Smart tips
101
- tips = []
102
- if any(d in ["Healthcare", "Finance", "Legal"] for d in domains):
103
- tips.append("🔒 **Zero Data Retention (ZDR)** - For regulated domains, enable ZDR on OpenAI/Anthropic/Google or use on-prem.")
104
- if latency == "< 500 ms (Instant)":
105
- tips.append("⚡ **Pick a smaller distilled variant** - Sort by 'likes' and look for 7B/8B versions of the top model.")
106
- if context_size == "32K - 200K tokens (Long)":
107
- tips.append("📚 **Add a RAG layer** - Even for long-context models, pair with Pinecone/Weaviate/pgvector for accuracy.")
108
- if "Style fine-tuning" in customization:
109
- tips.append("🎨 **Fine-tune with QLoRA** - Take the top model from the table above and fine-tune on 1k-5k domain examples.")
110
- if "RAG + Tool Calling" in customization:
111
- tips.append("🔧 **Enable Tool Calling** - Most top models support function calling / tool use. Check the model card for schema.")
112
- if not tips:
113
- tips.append("✨ Start with the #1 model in the table above and iterate. A great system prompt gets you 80% of the way.")
114
-
115
- tips_text = (NL + "- ").join(tips)
116
-
117
- how_to = ("### 📋 Your 3-Step Rollout Guide" + NL
118
- + "1. **Sandbox (Week 1):** Clone the top 3 models from the table above. Run 50-100 real queries from your dataset." + NL
119
- + "2. **Evaluate (Week 2):** Score on accuracy, latency, and cost per 1K tokens. Eliminate bottom performers." + NL
120
- + "3. **Deploy (Week 3):** Integrate the winner via API or self-hosted endpoint. Set up monitoring with LangSmith or Helicone." + NL
121
- )
122
-
123
- cta = (
124
- "---" + NL
125
- + "💡 **Need help shipping this fast?** [Book a free 30-min strategy call with AnkTechsol](https://anktechsol.com) "
126
- + "- we'll map your AI stack, estimate costs, and give you a production roadmap. No fluff."
127
- )
128
-
129
- tasks_label = ", ".join(f"`{t}`" for t in unique_tasks)
130
- license_label = f"license: `{license_filter}`" if license_filter else "all licenses"
131
-
132
- summary = (
133
- "## 🎉 Your Live AI Model Strategy" + NL + NL
134
- + "### 📦 Top Models on HuggingFace Hub Right Now" + NL
135
- + f"*Live from HF Hub API | Tasks: {tasks_label} | Filter: {license_label} | Sorted by downloads*" + NL + NL
136
- + model_table + NL + NL
137
- + "### 🗺️ Best Deployment Path" + NL
138
- + deploy_path + NL + NL
139
- + "### 💡 Pro-Tips for Your Use Case" + NL
140
- + "- " + tips_text + NL + NL
141
- + how_to + NL
142
- + "---" + NL
143
- + cta
144
- )
145
- return summary
146
-
147
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="orange", secondary_hue="slate"), title="AI Model Picker | AnkTechsol") as demo:
148
- gr.Markdown("# 🚀 AI Model Selection Wizard")
149
- gr.Markdown("**Pick the perfect AI brain for your use case.** This tool queries the HuggingFace Hub live and returns the top trending models for your exact task - no hardcoded lists. By [AnkTechsol](https://anktechsol.com).")
150
- with gr.Row():
151
- with gr.Column(scale=1):
152
- gr.Markdown("### 🔍 Step 1: Describe Your Task")
153
- modality = gr.CheckboxGroup(label="What inputs are you working with?", choices=["Text in -> text out", "Images in (docs, UI, scans)", "Audio in (speech)", "Structured data (tables, logs)", "Code"])
154
- outputs = gr.CheckboxGroup(label="What output do you need?", choices=["Natural language answer / summary", "Classification / tagging", "Field extraction from text/PDF", "Content generation (copy, emails)", "Scoring / ranking / decision"])
155
- domains = gr.CheckboxGroup(label="Your Industry / Domain", choices=["General / consumer", "Ecommerce / SaaS", "Finance", "Healthcare", "Legal", "Internal enterprise knowledge"])
156
- regulated = gr.CheckboxGroup(label="Data Sensitivity", choices=["Yes - contains PII, PHI, or financial data", "No - mostly public or non-sensitive data"])
157
- with gr.Column(scale=1):
158
- gr.Markdown("### ⚙️ Step 2: Set Your Constraints")
159
- data_sensitivity = gr.Radio(label="Data Privacy Requirements", choices=["Standard SaaS API is fine", "Must stay in a specific cloud region", "Strict: prefer on-prem / VPC only"], value="Standard SaaS API is fine")
160
- volume = gr.Radio(label="Expected Daily Request Volume", choices=["< 1,000", "1,000 - 100,000", "100,000+"], value="< 1,000")
161
- latency = gr.Radio(label="Latency Requirement", choices=["< 500 ms (Instant)", "0.5 - 5 s (Standard)", "> 5 s (Batch)"], value="0.5 - 5 s (Standard)")
162
- context_size = gr.Radio(label="Max Context Window Needed", choices=["< 4K tokens (Short)", "4K - 32K tokens (Medium)", "32K - 200K tokens (Long)"], value="4K - 32K tokens (Medium)")
163
- customization = gr.CheckboxGroup(label="Customization Needs", choices=["Prompt engineering only", "Style fine-tuning", "RAG + Tool Calling"])
164
- submit_btn = gr.Button("✨ Fetch Live Models and Generate My Strategy", variant="primary", size="lg")
165
- gr.Markdown("> 🕐 *Querying HuggingFace Hub live - may take 5-10 seconds. Please wait after clicking.*")
166
- gr.Markdown("---")
167
- output = gr.Markdown(label="Your Live AI Strategy")
168
- submit_btn.click(fn=recommend_model, inputs=[modality, outputs, domains, regulated, data_sensitivity, volume, latency, context_size, customization], outputs=output)
169
- gr.Markdown("---")
170
- gr.Markdown("### 🛠️ Why Teams Trust AnkTechsol")
171
- gr.Markdown("We help startups and enterprises go from AI confusion to production-grade AI systems. Fine-tuning, RAG pipelines, GPU inferencing as a service - we deliver.")
172
- gr.Markdown("**[Visit anktechsol.com](https://anktechsol.com) | [LinkedIn](https://www.linkedin.com/company/anktechsol)**")
173
-
174
- if __name__ == "__main__":
175
- demo.launch()
 
1
+ Final fix: Lead form + Email CTA colab@anktechsol.com