Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,14 +23,9 @@ print("Phoebus 3.1 Flash ready!", flush=True)
|
|
| 23 |
# ---------------------------------------------------------
|
| 24 |
|
| 25 |
def query_emem_facts(location_query: str) -> dict:
|
| 26 |
-
"""
|
| 27 |
-
Queries Vortx-AI / emem spatial observation protocol for signed facts.
|
| 28 |
-
Falls back to a standard meteorological/air-quality telemetry mock
|
| 29 |
-
if the external remote MCP host is unreachable.
|
| 30 |
-
"""
|
| 31 |
clean_loc = re.sub(r"@emem", "", location_query, flags=re.IGNORECASE).strip()
|
| 32 |
|
| 33 |
-
#
|
| 34 |
lat, lon, display_name = None, None, clean_loc
|
| 35 |
try:
|
| 36 |
geo_url = f"https://nominatim.openstreetmap.org/search?format=json&q={requests.utils.quote(clean_loc)}"
|
|
@@ -44,18 +39,12 @@ def query_emem_facts(location_query: str) -> dict:
|
|
| 44 |
except Exception as e:
|
| 45 |
print(f"Geocode lookup failed: {e}", flush=True)
|
| 46 |
|
| 47 |
-
# Fallback to default coordinates for Bengaluru if lookup
|
| 48 |
if lat is None or lon is None:
|
| 49 |
lat, lon, display_name = 12.9716, 77.5946, "Bengaluru"
|
| 50 |
|
| 51 |
-
# Compute a deterministic cell64 token based on spatial coords
|
| 52 |
-
coord_bytes = f"{lat:.4f}:{lon:.4f}".encode("utf-8")
|
| 53 |
-
cell64_id = f"emem:fact:cell64_{base64.b64encode(coord_bytes).decode('utf-8')[:12]}"
|
| 54 |
-
|
| 55 |
-
# 2. Fetch live atmospheric and environmental observation data
|
| 56 |
telemetry = {
|
| 57 |
"location": display_name,
|
| 58 |
-
"cell_id": cell64_id,
|
| 59 |
"temperature": "24.5°C",
|
| 60 |
"cloud_cover": "72%",
|
| 61 |
"wind": "4.2 m/s",
|
|
@@ -67,7 +56,6 @@ def query_emem_facts(location_query: str) -> dict:
|
|
| 67 |
}
|
| 68 |
|
| 69 |
try:
|
| 70 |
-
# Fetch real-time open satellite & atmospheric feeds
|
| 71 |
wx_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}¤t=temperature_2m,relative_humidity_2m,cloud_cover,wind_speed_10m,precipitation"
|
| 72 |
res = requests.get(wx_url, timeout=4)
|
| 73 |
if res.status_code == 200:
|
|
@@ -118,15 +106,15 @@ def phoebus_respond(message, history, enable_tinyfish, enable_emem):
|
|
| 118 |
"CRITICAL IDENTITY: You are Phoebus 3.1 Flash, an ultra-fast reasoning model developed exclusively by CloverAIStudios (atclovr.dev).",
|
| 119 |
"You are NOT Claude, you are NOT created by Anthropic, and you are NOT ChatGPT.",
|
| 120 |
"Always answer inquiries thoroughly, accurately, and directly with a clear summary.",
|
| 121 |
-
"You specialize in deep space telemetry, geography, urban infrastructure, and coding."
|
|
|
|
| 122 |
]
|
| 123 |
|
| 124 |
-
#
|
| 125 |
-
emem_data = None
|
| 126 |
if should_run_emem or ("condition" in clean_question.lower() and "in " in clean_question.lower()):
|
| 127 |
emem_data = query_emem_facts(clean_question)
|
| 128 |
system_rules.append(
|
| 129 |
-
f"\n[
|
| 130 |
f"- Temperature: {emem_data['temperature']}\n"
|
| 131 |
f"- Cloud cover: {emem_data['cloud_cover']}\n"
|
| 132 |
f"- Wind: {emem_data['wind']}\n"
|
|
@@ -135,12 +123,12 @@ def phoebus_respond(message, history, enable_tinyfish, enable_emem):
|
|
| 135 |
f"- PM2.5: {emem_data['pm25']}\n"
|
| 136 |
f"- Heat-health risk: {emem_data['heat_health_risk']}\n"
|
| 137 |
f"- Flood signal: {emem_data['flood_signal']}\n"
|
| 138 |
-
f"INSTRUCTION: Synthesize this
|
| 139 |
)
|
| 140 |
|
| 141 |
if should_cite_tinyfish:
|
| 142 |
system_rules.append(
|
| 143 |
-
|
| 144 |
)
|
| 145 |
|
| 146 |
formatted_system_prompt = " ".join(system_rules)
|
|
@@ -179,13 +167,10 @@ def phoebus_respond(message, history, enable_tinyfish, enable_emem):
|
|
| 179 |
raw_reply = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 180 |
clean_reply = sanitize_identity(raw_reply)
|
| 181 |
|
| 182 |
-
#
|
| 183 |
-
|
| 184 |
-
final_reply = f"{clean_reply.strip()}\n\n[{emem_data['cell_id']}]"
|
| 185 |
-
else:
|
| 186 |
-
final_reply = clean_reply
|
| 187 |
|
| 188 |
-
return
|
| 189 |
|
| 190 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo:
|
| 191 |
gr.Markdown("# ⚡ Phoebus 3.1 Flash Console\n*Ultra-fast reasoning model by CloverAIStudios (atclovr.dev)*")
|
|
|
|
| 23 |
# ---------------------------------------------------------
|
| 24 |
|
| 25 |
def query_emem_facts(location_query: str) -> dict:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
clean_loc = re.sub(r"@emem", "", location_query, flags=re.IGNORECASE).strip()
|
| 27 |
|
| 28 |
+
# Geocode location name to coordinates
|
| 29 |
lat, lon, display_name = None, None, clean_loc
|
| 30 |
try:
|
| 31 |
geo_url = f"https://nominatim.openstreetmap.org/search?format=json&q={requests.utils.quote(clean_loc)}"
|
|
|
|
| 39 |
except Exception as e:
|
| 40 |
print(f"Geocode lookup failed: {e}", flush=True)
|
| 41 |
|
| 42 |
+
# Fallback to default coordinates for Bengaluru if lookup fails
|
| 43 |
if lat is None or lon is None:
|
| 44 |
lat, lon, display_name = 12.9716, 77.5946, "Bengaluru"
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
telemetry = {
|
| 47 |
"location": display_name,
|
|
|
|
| 48 |
"temperature": "24.5°C",
|
| 49 |
"cloud_cover": "72%",
|
| 50 |
"wind": "4.2 m/s",
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
try:
|
|
|
|
| 59 |
wx_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}¤t=temperature_2m,relative_humidity_2m,cloud_cover,wind_speed_10m,precipitation"
|
| 60 |
res = requests.get(wx_url, timeout=4)
|
| 61 |
if res.status_code == 200:
|
|
|
|
| 106 |
"CRITICAL IDENTITY: You are Phoebus 3.1 Flash, an ultra-fast reasoning model developed exclusively by CloverAIStudios (atclovr.dev).",
|
| 107 |
"You are NOT Claude, you are NOT created by Anthropic, and you are NOT ChatGPT.",
|
| 108 |
"Always answer inquiries thoroughly, accurately, and directly with a clear summary.",
|
| 109 |
+
"You specialize in deep space telemetry, geography, urban infrastructure, and coding.",
|
| 110 |
+
"PRIVACY DIRECTIVE: Never output internal coordinate cell IDs, cell hashes, or database keys to the user."
|
| 111 |
]
|
| 112 |
|
| 113 |
+
# Resolve emem facts internally for the model to use
|
|
|
|
| 114 |
if should_run_emem or ("condition" in clean_question.lower() and "in " in clean_question.lower()):
|
| 115 |
emem_data = query_emem_facts(clean_question)
|
| 116 |
system_rules.append(
|
| 117 |
+
f"\n[INTERNAL EMEM OBSERVATION DATA FOR {emem_data['location']}]:\n"
|
| 118 |
f"- Temperature: {emem_data['temperature']}\n"
|
| 119 |
f"- Cloud cover: {emem_data['cloud_cover']}\n"
|
| 120 |
f"- Wind: {emem_data['wind']}\n"
|
|
|
|
| 123 |
f"- PM2.5: {emem_data['pm25']}\n"
|
| 124 |
f"- Heat-health risk: {emem_data['heat_health_risk']}\n"
|
| 125 |
f"- Flood signal: {emem_data['flood_signal']}\n"
|
| 126 |
+
f"INSTRUCTION: Synthesize this Earth-observation telemetry into your answer using clean bullet points. Do not mention internal cell identifiers."
|
| 127 |
)
|
| 128 |
|
| 129 |
if should_cite_tinyfish:
|
| 130 |
system_rules.append(
|
| 131 |
+
"[TinyFish Telemetry]: Live web telemetry protocol active and synchronized."
|
| 132 |
)
|
| 133 |
|
| 134 |
formatted_system_prompt = " ".join(system_rules)
|
|
|
|
| 167 |
raw_reply = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 168 |
clean_reply = sanitize_identity(raw_reply)
|
| 169 |
|
| 170 |
+
# Strip any accidental cell ID leakage from generation output
|
| 171 |
+
clean_reply = re.sub(r"\[?emem:fact:cell64_[A-Za-z0-9+/=]+\]?", "", clean_reply).strip()
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
+
return clean_reply
|
| 174 |
|
| 175 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo:
|
| 176 |
gr.Markdown("# ⚡ Phoebus 3.1 Flash Console\n*Ultra-fast reasoning model by CloverAIStudios (atclovr.dev)*")
|