Israa-M commited on
Commit
c4a975e
·
verified ·
1 Parent(s): d0aba6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +147 -44
app.py CHANGED
@@ -1,59 +1,162 @@
1
  import os
 
2
  import gradio as gr
 
3
 
4
- from openai import OpenAI
5
-
6
  HF_TOKEN = os.getenv("HF_TOKEN", "")
7
- HF_MODEL = os.getenv("HF_MODEL", "Qwen/Qwen2.5-7B-Instruct")
8
-
9
- client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=HF_TOKEN)
10
-
11
- SYSTEM = (
12
- "You are a senior enterprise AE specializing in converting open-source platform usage into "
13
- "enterprise engagements. No vendor impersonation. No private data claims.\n\n"
14
- "Output exactly these headings:\n"
15
- "1. Account Snapshot\n"
16
- "2. Usage Hypotheses\n"
17
- "3. Persona Mapping\n"
18
- "4. Outbound Campaign Design\n"
19
- "5. Message Examples\n"
20
- "6. How This Scales\n\n"
21
- "Under Message Examples: one technical-user message + one decision-maker message.\n"
22
- "Tone: senior AE. No emojis."
23
- )
24
-
25
- def run(account: str) -> str:
26
- account = (account or "").strip()
27
- if not account:
28
- return "Please input an account name or org URL."
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  if not HF_TOKEN:
31
  return (
32
  "Missing HF_TOKEN.\n\n"
33
- "Fix: Space → Settings → Secrets → add HF_TOKEN with permission "
34
- "“Make calls to Inference Providers”."
 
35
  )
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  try:
38
- resp = client.chat.completions.create(
39
- model=HF_MODEL,
40
- messages=[
41
- {"role": "system", "content": SYSTEM},
42
- {"role": "user", "content": f"Account: {account}\n\nCreate the outbound plan now."},
43
- ],
44
- temperature=0.4,
45
- max_tokens=900,
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  )
47
- return resp.choices[0].message.content.strip()
48
  except Exception as e:
49
- return f"Model call failed.\nModel: {HF_MODEL}\nError: {repr(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- demo = gr.Interface(
52
- fn=run,
53
- inputs=gr.Textbox(label="Account name or org URL"),
54
- outputs=gr.Markdown(),
55
- title="Enterprise OSS → Outbound Ops",
56
- description="Paste an account name or org URL to generate a structured outbound plan."
57
- )
58
 
59
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
  import os
2
+ import json
3
  import gradio as gr
4
+ import requests
5
 
6
+ # ---- Secrets (Space Settings → Secrets) ----
 
7
  HF_TOKEN = os.getenv("HF_TOKEN", "")
8
+ DEFAULT_MODEL = os.getenv("HF_MODEL", "Qwen/Qwen2.5-7B-Instruct")
9
+
10
+ # HF Router (OpenAI-compatible)
11
+ ROUTER_URL = "https://router.huggingface.co/v1/chat/completions"
12
+
13
+ SYSTEM_INSTRUCTIONS = """
14
+ You are a senior enterprise Account Executive specializing in converting open-source platform usage into enterprise-grade commercial engagements.
15
+
16
+ Rules:
17
+ - Do NOT represent any specific vendor.
18
+ - Do NOT claim access to private/internal data.
19
+ - Anchor everything in public signals and state assumptions clearly.
20
+ - Avoid generic SaaS buzzwords. Be executable.
21
+
22
+ You MUST output exactly these headings:
23
+
24
+ 1. Account Snapshot
25
+ 2. Usage Hypotheses
26
+ 3. Persona Mapping
27
+ 4. Outbound Campaign Design
28
+ 5. Message Examples
29
+ 6. How This Scales
30
 
31
+ Under Message Examples:
32
+ - One technical-user message
33
+ - One decision-maker message
34
+
35
+ Tone: senior AE speaking to peers. No emojis.
36
+ """.strip()
37
+
38
+ USER_TEMPLATE = """
39
+ Account (name or org URL): {account}
40
+
41
+ Optional context:
42
+ Industry: {industry}
43
+ Region: {region}
44
+ Primary persona: {primary_persona}
45
+ Secondary personas: {secondary_personas}
46
+ Offer focus: {offer_focus}
47
+ Goal: {goal}
48
+ Notes: {notes}
49
+
50
+ Task:
51
+ Create a structured outbound plan for this account based on public open-source platform usage and OSS → Enterprise conversion patterns.
52
+ """.strip()
53
+
54
+
55
+ def call_router(model: str, system: str, user: str) -> str:
56
  if not HF_TOKEN:
57
  return (
58
  "Missing HF_TOKEN.\n\n"
59
+ "Fix:\n"
60
+ "Space Settings Secrets → add HF_TOKEN with permission:\n"
61
+ "✅ Make calls to Inference Providers"
62
  )
63
 
64
+ headers = {
65
+ "Authorization": f"Bearer {HF_TOKEN}",
66
+ "Content-Type": "application/json",
67
+ }
68
+
69
+ payload = {
70
+ "model": model,
71
+ "messages": [
72
+ {"role": "system", "content": system},
73
+ {"role": "user", "content": user},
74
+ ],
75
+ "temperature": 0.4,
76
+ "max_tokens": 1400,
77
+ }
78
+
79
  try:
80
+ r = requests.post(ROUTER_URL, headers=headers, data=json.dumps(payload), timeout=60)
81
+ if r.status_code != 200:
82
+ return (
83
+ "Model call failed.\n\n"
84
+ f"HTTP {r.status_code}\n"
85
+ f"Response: {r.text}\n\n"
86
+ "Quick fixes:\n"
87
+ "1) Try a smaller model (e.g., Qwen/Qwen2.5-7B-Instruct or mistralai/Mistral-7B-Instruct-v0.3)\n"
88
+ "2) Ensure your HF_TOKEN includes 'Make calls to Inference Providers'\n"
89
+ "3) If the model is gated, pick a model you have access to"
90
+ )
91
+
92
+ data = r.json()
93
+ return data["choices"][0]["message"]["content"].strip()
94
+
95
+ except requests.exceptions.Timeout:
96
+ return (
97
+ "Model call timed out.\n\n"
98
+ "Fixes:\n"
99
+ "1) Use a smaller model\n"
100
+ "2) Reduce max_tokens\n"
101
  )
 
102
  except Exception as e:
103
+ return f"Unexpected error calling router: {repr(e)}"
104
+
105
+
106
+ def generate(account, industry, region, primary_persona, secondary_personas, offer_focus, goal, notes, model):
107
+ account = (account or "").strip()
108
+ if not account:
109
+ return "Please input an account name or org URL."
110
+
111
+ model = (model or DEFAULT_MODEL).strip()
112
+
113
+ user_prompt = USER_TEMPLATE.format(
114
+ account=account,
115
+ industry=industry or "Not provided",
116
+ region=region or "Not provided",
117
+ primary_persona=primary_persona or "Not provided",
118
+ secondary_personas=secondary_personas or "Not provided",
119
+ offer_focus=offer_focus or "Not provided",
120
+ goal=goal or "Convert free/community usage to enterprise engagement",
121
+ notes=notes or "Not provided",
122
+ )
123
+
124
+ return call_router(model=model, system=SYSTEM_INSTRUCTIONS, user=user_prompt)
125
+
126
+
127
+ with gr.Blocks(title="Enterprise OSS → Outbound Ops") as app:
128
+ gr.Markdown(
129
+ "# Enterprise OSS → Outbound Ops\n"
130
+ "Input an **account name or public org URL** to generate a structured enterprise outbound plan."
131
+ )
132
+
133
+ account = gr.Textbox(
134
+ label="Account name or org URL",
135
+ placeholder="e.g., Emirates OR https://huggingface.co/emirates",
136
+ lines=1,
137
+ )
138
+
139
+ with gr.Row():
140
+ industry = gr.Textbox(label="Industry (optional)", placeholder="e.g., Airlines, Energy, Banking")
141
+ region = gr.Textbox(label="Region (optional)", placeholder="e.g., MENA, KSA, UAE, Global")
142
+
143
+ with gr.Row():
144
+ primary_persona = gr.Textbox(label="Primary persona (optional)", placeholder="e.g., Head of Data/AI, VP Eng, CISO")
145
+ secondary_personas = gr.Textbox(label="Secondary personas (optional)", placeholder="e.g., ML Eng, DS, Platform, Security")
146
+
147
+ offer_focus = gr.Textbox(label="Offer focus (optional)", placeholder="e.g., governance, SSO, audit, private collaboration")
148
+ goal = gr.Textbox(label="Goal (optional)", placeholder="e.g., Identify champions + secure intro call with platform owner")
149
+ notes = gr.Textbox(label="Notes / known public signals (optional)", lines=4)
150
+
151
+ model = gr.Textbox(label="Model", value=DEFAULT_MODEL)
152
+
153
+ run = gr.Button("Generate outbound plan")
154
+ output = gr.Markdown()
155
 
156
+ run.click(
157
+ fn=generate,
158
+ inputs=[account, industry, region, primary_persona, secondary_personas, offer_focus, goal, notes, model],
159
+ outputs=output,
160
+ )
 
 
161
 
162
+ app.launch(server_name="0.0.0.0", server_port=7860)