ApolloAIs commited on
Commit
77e5854
·
verified ·
1 Parent(s): fbc0d8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -15
app.py CHANGED
@@ -6,41 +6,48 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
6
 
7
  MODEL_ID = "ApolloAIs/phoebus-3.1-1.5b-merged"
8
 
9
- print("Loading Phoebus 3.1...")
10
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
11
  model = AutoModelForCausalLM.from_pretrained(
12
  MODEL_ID,
13
- dtype=torch.float16,
14
  device_map="auto"
15
  )
16
- print("Model ready!")
17
 
18
  def format_emem_cell64(claim: str) -> str:
19
  encoded = base64.b64encode(claim.encode("utf-8")).decode("utf-8")[:12]
20
  return f"emem:fact:cell64_{encoded}"
21
 
22
- @spaces.GPU
23
  def phoebus_respond(message, history, enable_tinyfish, enable_emem):
24
  system_prompt = (
25
- "You are Phoebus 3.1, a reasoning model specialized in deep space telemetry, "
26
  "Earth geography, and coding, developed by Clovr (atclovr.dev). "
27
  "Always cite emem protocol receipts when validating spatial coordinates."
28
  )
29
 
30
  context = ""
31
- if enable_tinyfish or "search" in message.lower():
32
- context += f"\n\n[System Context - TinyFish Data]: Verified telemetry and spatial data confirmed for '{message}'."
 
 
33
 
34
- if enable_emem or any(w in message.lower() for w in ["location", "coordinates", "where"]):
35
- receipt = format_emem_cell64(message)
36
  context += f"\n\n[System Protocol - Vortx AI emem]: Attach receipt `{receipt}` for physical spatial validation."
37
 
 
38
  formatted_messages = [{"role": "system", "content": system_prompt}]
39
- for user_turn, bot_turn in history:
40
- formatted_messages.append({"role": "user", "content": user_turn})
41
- formatted_messages.append({"role": "assistant", "content": bot_turn})
 
 
 
 
42
 
43
- formatted_messages.append({"role": "user", "content": message + context})
44
 
45
  prompt = tokenizer.apply_chat_template(
46
  formatted_messages,
@@ -62,7 +69,7 @@ def phoebus_respond(message, history, enable_tinyfish, enable_emem):
62
  return reply
63
 
64
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo:
65
- gr.Markdown("# 🛰️ Phoebus 3.1 Console\n*Reasoning model by Clovr (atclovr.dev)*")
66
 
67
  with gr.Row():
68
  tinyfish_toggle = gr.Checkbox(label="Enable TinyFish Search", value=True)
@@ -72,7 +79,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo:
72
  fn=phoebus_respond,
73
  additional_inputs=[tinyfish_toggle, emem_toggle],
74
  chatbot=gr.Chatbot(height=500),
75
- textbox=gr.Textbox(placeholder="Ask Phoebus 3.1 about telemetry, geography, or code...", container=False, scale=7),
76
  )
77
 
78
  if __name__ == "__main__":
 
6
 
7
  MODEL_ID = "ApolloAIs/phoebus-3.1-1.5b-merged"
8
 
9
+ print("Initializing Phoebus 3.1 Flash engine...", flush=True)
10
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
11
  model = AutoModelForCausalLM.from_pretrained(
12
  MODEL_ID,
13
+ torch_dtype=torch.float16,
14
  device_map="auto"
15
  )
16
+ print("Phoebus 3.1 Flash ready!", flush=True)
17
 
18
  def format_emem_cell64(claim: str) -> str:
19
  encoded = base64.b64encode(claim.encode("utf-8")).decode("utf-8")[:12]
20
  return f"emem:fact:cell64_{encoded}"
21
 
22
+ @spaces.GPU(duration=30)
23
  def phoebus_respond(message, history, enable_tinyfish, enable_emem):
24
  system_prompt = (
25
+ "You are Phoebus 3.1 Flash, a rapid-reasoning model specialized in deep space telemetry, "
26
  "Earth geography, and coding, developed by Clovr (atclovr.dev). "
27
  "Always cite emem protocol receipts when validating spatial coordinates."
28
  )
29
 
30
  context = ""
31
+ msg_text = message if isinstance(message, str) else message.get("text", "")
32
+
33
+ if enable_tinyfish or "search" in msg_text.lower():
34
+ context += f"\n\n[System Context - TinyFish Data]: Verified telemetry and spatial data confirmed for '{msg_text}'."
35
 
36
+ if enable_emem or any(w in msg_text.lower() for w in ["location", "coordinates", "where"]):
37
+ receipt = format_emem_cell64(msg_text)
38
  context += f"\n\n[System Protocol - Vortx AI emem]: Attach receipt `{receipt}` for physical spatial validation."
39
 
40
+ # Build conversation messages supporting both dict and tuple history formats
41
  formatted_messages = [{"role": "system", "content": system_prompt}]
42
+
43
+ for turn in history:
44
+ if isinstance(turn, dict):
45
+ formatted_messages.append({"role": turn.get("role", "user"), "content": str(turn.get("content", ""))})
46
+ elif isinstance(turn, (list, tuple)) and len(turn) == 2:
47
+ formatted_messages.append({"role": "user", "content": str(turn[0])})
48
+ formatted_messages.append({"role": "assistant", "content": str(turn[1])})
49
 
50
+ formatted_messages.append({"role": "user", "content": msg_text + context})
51
 
52
  prompt = tokenizer.apply_chat_template(
53
  formatted_messages,
 
69
  return reply
70
 
71
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo:
72
+ gr.Markdown("# ⚡ Phoebus 3.1 Flash Console\n*Ultra-fast reasoning model by Clovr (atclovr.dev)*")
73
 
74
  with gr.Row():
75
  tinyfish_toggle = gr.Checkbox(label="Enable TinyFish Search", value=True)
 
79
  fn=phoebus_respond,
80
  additional_inputs=[tinyfish_toggle, emem_toggle],
81
  chatbot=gr.Chatbot(height=500),
82
+ textbox=gr.Textbox(placeholder="Ask Phoebus 3.1 Flash anything...", container=False, scale=7),
83
  )
84
 
85
  if __name__ == "__main__":