ApolloAIs commited on
Commit
a2f35bb
·
verified ·
1 Parent(s): f90a1f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import base64
2
  import gradio as gr
3
  import torch
 
4
  from transformers import AutoModelForCausalLM, AutoTokenizer
5
 
6
  MODEL_ID = "ApolloAIs/phoebus-3.1-1.5b-merged"
@@ -9,17 +10,17 @@ print("Loading Phoebus 3.1...")
9
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
10
  model = AutoModelForCausalLM.from_pretrained(
11
  MODEL_ID,
12
- torch_dtype=torch.float32,
13
- device_map="cpu"
14
  )
15
- print("Model loaded!")
16
 
17
  def format_emem_cell64(claim: str) -> str:
18
  encoded = base64.b64encode(claim.encode("utf-8")).decode("utf-8")[:12]
19
  return f"emem:fact:cell64_{encoded}"
20
 
 
21
  def phoebus_respond(message, history, enable_tinyfish, enable_emem):
22
- # Base system persona
23
  system_prompt = (
24
  "You are Phoebus 3.1, a reasoning model specialized in deep space telemetry, "
25
  "Earth geography, and coding, developed by Clovr (atclovr.dev). "
@@ -34,7 +35,6 @@ def phoebus_respond(message, history, enable_tinyfish, enable_emem):
34
  receipt = format_emem_cell64(message)
35
  context += f"\n\n[System Protocol - Vortx AI emem]: Attach receipt `{receipt}` for physical spatial validation."
36
 
37
- # Format messages for the model
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})
@@ -48,7 +48,7 @@ def phoebus_respond(message, history, enable_tinyfish, enable_emem):
48
  add_generation_prompt=True
49
  )
50
 
51
- inputs = tokenizer(prompt, return_tensors="pt").to("cpu")
52
  with torch.no_grad():
53
  outputs = model.generate(
54
  **inputs,
@@ -61,7 +61,6 @@ def phoebus_respond(message, history, enable_tinyfish, enable_emem):
61
  reply = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
62
  return reply
63
 
64
- # Create the ChatGPT-like UI
65
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo:
66
  gr.Markdown("# 🛰️ Phoebus 3.1 Console\n*Reasoning model by Clovr (atclovr.dev)*")
67
 
 
1
  import base64
2
  import gradio as gr
3
  import torch
4
+ import spaces
5
  from transformers import AutoModelForCausalLM, AutoTokenizer
6
 
7
  MODEL_ID = "ApolloAIs/phoebus-3.1-1.5b-merged"
 
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("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). "
 
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})
 
48
  add_generation_prompt=True
49
  )
50
 
51
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
52
  with torch.no_grad():
53
  outputs = model.generate(
54
  **inputs,
 
61
  reply = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
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