v0idalism commited on
Commit
c5d2acd
·
verified ·
1 Parent(s): d4b378f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -26,6 +26,7 @@ MODES = {
26
  ),
27
  }
28
 
 
29
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
30
  model = AutoModelForCausalLM.from_pretrained(
31
  MODEL_ID,
@@ -34,6 +35,7 @@ model = AutoModelForCausalLM.from_pretrained(
34
  trust_remote_code=True
35
  )
36
  pipe = TextGenerationPipeline(model=model, tokenizer=tokenizer, device=-1)
 
37
 
38
  # ----------- CHAT FUNCTION -----------
39
  def chat(user_message: str):
@@ -41,7 +43,7 @@ def chat(user_message: str):
41
  if not user_message:
42
  return "[Error: Empty prompt]"
43
 
44
- # Mode parsing
45
  if "::" in user_message:
46
  mode_key, msg = user_message.split("::", 1)
47
  mode_key = mode_key.strip().upper()
@@ -72,21 +74,24 @@ iface = gr.Interface(
72
  inputs=gr.Textbox(lines=2, placeholder="Type your message…"),
73
  outputs=gr.Textbox(),
74
  title="BLACKLIGHT by v0id",
75
- description="Brutalist • Minimal • Precise — Multiple modes supported. Use TRUTH::, SURGE::, NULL::",
76
  )
77
 
78
- # ----------- FASTAPI + SHIM ENDPOINT -----------
79
  app = FastAPI()
80
 
81
  @app.post("/run/predict")
82
  async def predict(request: Request):
83
  try:
84
  body = await request.json()
85
- user_message = body.get("data", [""])[0]
 
 
 
86
  reply = chat(user_message)
87
  return JSONResponse({"data": [reply]})
88
  except Exception as e:
89
  return JSONResponse({"error": str(e)}, status_code=500)
90
 
91
- # Mount Gradio at root so Spaces boots
92
  app = gr.mount_gradio_app(app, iface, path="/")
 
26
  ),
27
  }
28
 
29
+ print("Loading model...")
30
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
31
  model = AutoModelForCausalLM.from_pretrained(
32
  MODEL_ID,
 
35
  trust_remote_code=True
36
  )
37
  pipe = TextGenerationPipeline(model=model, tokenizer=tokenizer, device=-1)
38
+ print("Model loaded.")
39
 
40
  # ----------- CHAT FUNCTION -----------
41
  def chat(user_message: str):
 
43
  if not user_message:
44
  return "[Error: Empty prompt]"
45
 
46
+ # Detect mode
47
  if "::" in user_message:
48
  mode_key, msg = user_message.split("::", 1)
49
  mode_key = mode_key.strip().upper()
 
74
  inputs=gr.Textbox(lines=2, placeholder="Type your message…"),
75
  outputs=gr.Textbox(),
76
  title="BLACKLIGHT by v0id",
77
+ description="Brutalist • Minimal • Precise — Modes: TRUTH::, SURGE::, NULL:: (or leave blank for TRUTH)",
78
  )
79
 
80
+ # ----------- FASTAPI APP -----------
81
  app = FastAPI()
82
 
83
  @app.post("/run/predict")
84
  async def predict(request: Request):
85
  try:
86
  body = await request.json()
87
+ if isinstance(body.get("data"), list) and len(body["data"]) > 0:
88
+ user_message = body["data"][0]
89
+ else:
90
+ user_message = ""
91
  reply = chat(user_message)
92
  return JSONResponse({"data": [reply]})
93
  except Exception as e:
94
  return JSONResponse({"error": str(e)}, status_code=500)
95
 
96
+ # Mount Gradio at `/` so Hugging Face Spaces auto-starts
97
  app = gr.mount_gradio_app(app, iface, path="/")