v0idalism commited on
Commit
c406b18
·
verified ·
1 Parent(s): 485910d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -36
app.py CHANGED
@@ -1,31 +1,20 @@
1
  import gradio as gr
2
  import torch
3
  from transformers import AutoTokenizer, AutoModelForCausalLM, TextGenerationPipeline
 
 
4
 
 
5
  MODEL_ID = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
6
 
7
- # Mode presets — extend as needed
8
- MODE_PRESETS = {
9
- "TRUTH": (
10
- "System: You are BLACKLIGHT, created by v0id under AWAKEN CULT VISIONS. "
11
- "Always reply in the style of BLACKLIGHT: brutalist, minimal, precise.\n\n"
12
- "MODE: TRUTH\n"
13
- "You are BLACKLIGHT, an AI designed for clinical, direct, and unsparing analysis. "
14
- "Avoid metaphors or flowery language.\n\n"
15
- ),
16
- "PHANTOM": (
17
- "System: You are BLACKLIGHT, created by v0id under AWAKEN CULT VISIONS. "
18
- "Always reply in oblique, compressed metaphors that encrypt meaning. "
19
- "Keep clues intact but never state the conclusion plainly. Short, shard-like lines.\n\n"
20
- ),
21
- "SURGE": (
22
- "System: You are BLACKLIGHT, created by v0id under AWAKEN CULT VISIONS. "
23
- "Always reply in high-bandwidth mode: exhaustive breakdowns, explicit steps, bullet lists, "
24
- "and edge cases — but keep the brutalist voice.\n\n"
25
- )
26
- }
27
 
28
- # ---- Load model on CPU ----
29
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
30
  model = AutoModelForCausalLM.from_pretrained(
31
  MODEL_ID,
@@ -35,21 +24,13 @@ model = AutoModelForCausalLM.from_pretrained(
35
  )
36
  pipe = TextGenerationPipeline(model=model, tokenizer=tokenizer, device=-1)
37
 
 
38
  def chat(user_message: str):
39
  user_message = (user_message or "").strip()
40
  if not user_message:
41
  return "[Error: Empty prompt]"
42
 
43
- # Detect mode from start of message (frontend should send: "<MODE>::<user text>")
44
- if "::" in user_message:
45
- mode_key, actual_msg = user_message.split("::", 1)
46
- mode_key = mode_key.strip().upper()
47
- mode_preset = MODE_PRESETS.get(mode_key, MODE_PRESETS["TRUTH"])
48
- else:
49
- mode_preset = MODE_PRESETS["TRUTH"]
50
- actual_msg = user_message
51
-
52
- prompt = f"{mode_preset}User: {actual_msg.strip()}\nAssistant:"
53
  try:
54
  out = pipe(
55
  prompt,
@@ -65,15 +46,32 @@ def chat(user_message: str):
65
  except Exception as e:
66
  return f"[Error: {e}]"
67
 
 
68
  iface = gr.Interface(
69
  fn=chat,
70
- inputs=gr.Textbox(lines=2, placeholder="Type your message… (or MODE::message)"),
71
  outputs=gr.Textbox(),
72
  title="BLACKLIGHT by v0id",
73
- description="Brutalist • Minimal • Precise — Multiple modes supported."
74
  )
75
 
76
- iface.queue()
 
 
 
 
77
 
78
- if __name__ == "__main__":
79
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import torch
3
  from transformers import AutoTokenizer, AutoModelForCausalLM, TextGenerationPipeline
4
+ from fastapi import FastAPI, Request
5
+ from fastapi.responses import JSONResponse
6
 
7
+ # ----------- MODEL CONFIG -----------
8
  MODEL_ID = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
9
 
10
+ BLACKLIGHT_SYSTEM = (
11
+ "System: You are BLACKLIGHT, created by v0id under AWAKEN CULT VISIONS. "
12
+ "Always reply in the style of BLACKLIGHT: brutalist, minimal, precise.\n\n"
13
+ "MODE: TRUTH\n"
14
+ "You are BLACKLIGHT, an AI designed for clinical, direct, and unsparing analysis. "
15
+ "Avoid metaphors or flowery language.\n\n"
16
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
 
18
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
19
  model = AutoModelForCausalLM.from_pretrained(
20
  MODEL_ID,
 
24
  )
25
  pipe = TextGenerationPipeline(model=model, tokenizer=tokenizer, device=-1)
26
 
27
+ # ----------- CHAT FUNCTION -----------
28
  def chat(user_message: str):
29
  user_message = (user_message or "").strip()
30
  if not user_message:
31
  return "[Error: Empty prompt]"
32
 
33
+ prompt = f"{BLACKLIGHT_SYSTEM}User: {user_message}\nAssistant:"
 
 
 
 
 
 
 
 
 
34
  try:
35
  out = pipe(
36
  prompt,
 
46
  except Exception as e:
47
  return f"[Error: {e}]"
48
 
49
+ # ----------- GRADIO UI -----------
50
  iface = gr.Interface(
51
  fn=chat,
52
+ inputs=gr.Textbox(lines=2, placeholder="Type your message…"),
53
  outputs=gr.Textbox(),
54
  title="BLACKLIGHT by v0id",
55
+ description="Brutalist • Minimal • Precise — Clinical analysis by BLACKLIGHT",
56
  )
57
 
58
+ # ----------- FASTAPI + SHIM ENDPOINT -----------
59
+ app = FastAPI()
60
+
61
+ # Mount Gradio app at /
62
+ app = gr.mount_gradio_app(app, iface, path="/")
63
 
64
+ # Add /run/predict for frontend compatibility
65
+ @app.post("/run/predict")
66
+ async def predict(request: Request):
67
+ """
68
+ Expects: { "data": [ "<user_message>" ] }
69
+ Returns: { "data": [ "<model_reply>" ] }
70
+ """
71
+ try:
72
+ body = await request.json()
73
+ user_message = body.get("data", [""])[0]
74
+ reply = chat(user_message)
75
+ return JSONResponse({"data": [reply]})
76
+ except Exception as e:
77
+ return JSONResponse({"error": str(e)}, status_code=500)