Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,16 +13,21 @@ import torch
|
|
| 13 |
import gradio as gr
|
| 14 |
from sentence_transformers import SentenceTransformer, util as st_util
|
| 15 |
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
|
|
|
| 16 |
|
| 17 |
warnings.filterwarnings("ignore")
|
| 18 |
|
| 19 |
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 20 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 23 |
EMBED_MODEL_ID = "sentence-transformers/all-MiniLM-L6-v2"
|
| 24 |
GEN_MODEL_ID = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 25 |
-
GEN_MODEL_API = "
|
| 26 |
|
| 27 |
VENDOR_CATEGORIES = [
|
| 28 |
"Catering", "AV_Technology", "Venue", "Security",
|
|
@@ -42,7 +47,6 @@ CITIES = ["Beer Sheva", "Haifa", "Herzliya", "Jerusalem",
|
|
| 42 |
"Netanya", "Petah Tikva", "Ramat Gan", "Tel Aviv"]
|
| 43 |
SEASONS = ["Winter", "Spring", "Summer", "Fall"]
|
| 44 |
|
| 45 |
-
# Updated to include private events
|
| 46 |
EVENT_TYPES = [
|
| 47 |
"Annual Conference", "Award Ceremony", "Bar/Bat Mitzvah", "Brand Activation",
|
| 48 |
"Corporate Gala", "Family Reunion", "Investor Day", "Private Birthday",
|
|
@@ -159,15 +163,21 @@ if _gen_backend == "none":
|
|
| 159 |
|
| 160 |
def _call_llm(prompt: str, max_new_tokens: int = 450) -> str:
|
| 161 |
if _gen_backend == "api":
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
| 163 |
if _gen_backend == "local" and _gen_model is not None:
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
| 166 |
return "⚠️ Generation not available. Add HF_TOKEN as a Space Secret to enable."
|
| 167 |
|
| 168 |
def _prompt(system: str, user: str) -> str:
|
| 169 |
if _gen_backend == "api":
|
| 170 |
-
return f"<
|
| 171 |
return f"<|system|>\n{system}</s>\n<|user|>\n{user}</s>\n<|assistant|>\n"
|
| 172 |
|
| 173 |
def recommend_vendors(brief, city, season, budget, top_n=3):
|
|
@@ -209,7 +219,6 @@ def gen_run_of_show(ev_type, date, venue, city, guests, vendors, notes):
|
|
| 209 |
return _call_llm(_prompt("You are a senior event production manager. Write a detailed Run of Show using format HH:MM — Task.", f"Event: {ev_type}\nDate: {date}\nVenue: {venue}, {city}\nGuests: {guests:,}\nNotes: {notes or 'None'}\n\nVendors:\n{lines}"))
|
| 210 |
|
| 211 |
def gen_rfp(name, cat, specs, ev_type, date, city, guests, alloc_usd, notes):
|
| 212 |
-
# Prompt updated to be generic enough for private events
|
| 213 |
return _call_llm(_prompt("You are a professional event producer writing a formal RFP (Request for Proposal) email to a vendor.", f"Vendor: {name}\nCategory: {cat.replace('_', ' ')}\nEvent: {ev_type}\nDate: {date}\nLocation: {city}\nGuests: {guests:,}\nBudget: ${alloc_usd:,.0f}\nRequirements: {notes or 'Standard service'}"))
|
| 214 |
|
| 215 |
def _stars(r):
|
|
@@ -277,12 +286,6 @@ def _qs1(): return _qs(1)
|
|
| 277 |
def _qs2(): return _qs(2)
|
| 278 |
def _qs3(): return _qs(3)
|
| 279 |
|
| 280 |
-
import spaces
|
| 281 |
-
|
| 282 |
-
@spaces.GPU
|
| 283 |
-
def dummy_gpu_function():
|
| 284 |
-
pass
|
| 285 |
-
|
| 286 |
CSS = """
|
| 287 |
body, .gradio-container { background-color: #FAF7F2 !important; font-family: 'Inter', sans-serif !important; color: #2C1810 !important; }
|
| 288 |
.ps-header { background: linear-gradient(135deg, #3D2314 0%, #7A4E2D 60%, #B8895A 100%); border-radius: 16px; padding: 36px 40px; margin-bottom: 20px; box-shadow: 0 8px 32px rgba(61,35,20,.25); color: white; }
|
|
|
|
| 13 |
import gradio as gr
|
| 14 |
from sentence_transformers import SentenceTransformer, util as st_util
|
| 15 |
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
| 16 |
+
import spaces
|
| 17 |
|
| 18 |
warnings.filterwarnings("ignore")
|
| 19 |
|
| 20 |
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 21 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 22 |
|
| 23 |
+
@spaces.GPU
|
| 24 |
+
def dummy_gpu_function():
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 28 |
EMBED_MODEL_ID = "sentence-transformers/all-MiniLM-L6-v2"
|
| 29 |
GEN_MODEL_ID = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 30 |
+
GEN_MODEL_API = "HuggingFaceH4/zephyr-7b-beta"
|
| 31 |
|
| 32 |
VENDOR_CATEGORIES = [
|
| 33 |
"Catering", "AV_Technology", "Venue", "Security",
|
|
|
|
| 47 |
"Netanya", "Petah Tikva", "Ramat Gan", "Tel Aviv"]
|
| 48 |
SEASONS = ["Winter", "Spring", "Summer", "Fall"]
|
| 49 |
|
|
|
|
| 50 |
EVENT_TYPES = [
|
| 51 |
"Annual Conference", "Award Ceremony", "Bar/Bat Mitzvah", "Brand Activation",
|
| 52 |
"Corporate Gala", "Family Reunion", "Investor Day", "Private Birthday",
|
|
|
|
| 163 |
|
| 164 |
def _call_llm(prompt: str, max_new_tokens: int = 450) -> str:
|
| 165 |
if _gen_backend == "api":
|
| 166 |
+
try:
|
| 167 |
+
return _gen_client.text_generation(prompt, max_new_tokens=max_new_tokens, temperature=0.7, do_sample=True).strip()
|
| 168 |
+
except Exception as e:
|
| 169 |
+
return f"⚠️ API Error:\n{str(e)}\n\n(Please check if your HF_TOKEN is valid and has 'Read' access.)"
|
| 170 |
if _gen_backend == "local" and _gen_model is not None:
|
| 171 |
+
try:
|
| 172 |
+
out = _gen_model(prompt, max_new_tokens=max_new_tokens, do_sample=True, temperature=0.7, pad_token_id=_gen_tok.eos_token_id, return_full_text=False)
|
| 173 |
+
return out[0]["generated_text"].strip()
|
| 174 |
+
except Exception as e:
|
| 175 |
+
return f"⚠️ Local Model Error:\n{str(e)}"
|
| 176 |
return "⚠️ Generation not available. Add HF_TOKEN as a Space Secret to enable."
|
| 177 |
|
| 178 |
def _prompt(system: str, user: str) -> str:
|
| 179 |
if _gen_backend == "api":
|
| 180 |
+
return f"<|system|>\n{system}</s>\n<|user|>\n{user}</s>\n<|assistant|>\n"
|
| 181 |
return f"<|system|>\n{system}</s>\n<|user|>\n{user}</s>\n<|assistant|>\n"
|
| 182 |
|
| 183 |
def recommend_vendors(brief, city, season, budget, top_n=3):
|
|
|
|
| 219 |
return _call_llm(_prompt("You are a senior event production manager. Write a detailed Run of Show using format HH:MM — Task.", f"Event: {ev_type}\nDate: {date}\nVenue: {venue}, {city}\nGuests: {guests:,}\nNotes: {notes or 'None'}\n\nVendors:\n{lines}"))
|
| 220 |
|
| 221 |
def gen_rfp(name, cat, specs, ev_type, date, city, guests, alloc_usd, notes):
|
|
|
|
| 222 |
return _call_llm(_prompt("You are a professional event producer writing a formal RFP (Request for Proposal) email to a vendor.", f"Vendor: {name}\nCategory: {cat.replace('_', ' ')}\nEvent: {ev_type}\nDate: {date}\nLocation: {city}\nGuests: {guests:,}\nBudget: ${alloc_usd:,.0f}\nRequirements: {notes or 'Standard service'}"))
|
| 223 |
|
| 224 |
def _stars(r):
|
|
|
|
| 286 |
def _qs2(): return _qs(2)
|
| 287 |
def _qs3(): return _qs(3)
|
| 288 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
CSS = """
|
| 290 |
body, .gradio-container { background-color: #FAF7F2 !important; font-family: 'Inter', sans-serif !important; color: #2C1810 !important; }
|
| 291 |
.ps-header { background: linear-gradient(135deg, #3D2314 0%, #7A4E2D 60%, #B8895A 100%); border-radius: 16px; padding: 36px 40px; margin-bottom: 20px; box-shadow: 0 8px 32px rgba(61,35,20,.25); color: white; }
|