Create App.py
Browse files
App.py
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import torch
|
|
|
|
| 4 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 5 |
|
| 6 |
-
# ---
|
| 7 |
-
#
|
|
|
|
|
|
|
|
|
|
| 8 |
MODEL_DIR = "./buddha_v2_model"
|
| 9 |
BASE_MODEL = "mistralai/Mistral-7B-v0.1"
|
| 10 |
|
| 11 |
-
def
|
| 12 |
-
"""
|
| 13 |
-
Attempts to load the fine-tuned model.
|
| 14 |
-
Falls back to base model if training isn't finished.
|
| 15 |
-
"""
|
| 16 |
try:
|
| 17 |
path = MODEL_DIR if os.path.exists(MODEL_DIR) else BASE_MODEL
|
| 18 |
tokenizer = AutoTokenizer.from_pretrained(path)
|
|
@@ -20,72 +20,68 @@ def load_star_magic_model():
|
|
| 20 |
path,
|
| 21 |
device_map="auto",
|
| 22 |
torch_dtype=torch.float16,
|
| 23 |
-
load_in_4bit=True
|
| 24 |
)
|
| 25 |
return pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 26 |
except Exception as e:
|
| 27 |
-
print(f"Model load info: {e}")
|
| 28 |
return None
|
| 29 |
|
| 30 |
-
|
| 31 |
-
generator = load_star_magic_model()
|
| 32 |
|
| 33 |
def manifest_agent(name, element, focus):
|
| 34 |
"""
|
| 35 |
-
|
| 36 |
-
|
| 37 |
"""
|
| 38 |
-
prompt = f"""[INST] Role:
|
| 39 |
-
|
| 40 |
Input Name: {name}
|
| 41 |
Input Element: {element}
|
| 42 |
Input Focus: {focus}
|
| 43 |
|
| 44 |
-
Generate a
|
| 45 |
-
1.
|
| 46 |
-
2.
|
| 47 |
-
3.
|
| 48 |
-
4. Galactic Rank
|
| 49 |
[/INST]"""
|
| 50 |
|
| 51 |
if generator:
|
| 52 |
-
response = generator(prompt, max_new_tokens=
|
| 53 |
return response[0]['generated_text'].split("[/INST]")[-1].strip()
|
| 54 |
else:
|
| 55 |
-
|
| 56 |
-
return "System Calibration in Progress. The Forge is currently cooling down from a fine-tuning session. Please check back in a moment."
|
| 57 |
|
| 58 |
-
# --- UI Layout
|
| 59 |
-
with gr.Blocks(theme=gr.themes.
|
| 60 |
-
gr.Markdown("# 🌌 Star Magic
|
| 61 |
-
gr.Markdown("
|
| 62 |
|
| 63 |
with gr.Row():
|
| 64 |
-
with gr.Column():
|
| 65 |
-
agent_name = gr.Textbox(label="
|
| 66 |
-
agent_element = gr.
|
| 67 |
-
label="
|
| 68 |
-
choices=["Void", "Solar", "
|
| 69 |
value="Void"
|
| 70 |
)
|
| 71 |
-
agent_focus = gr.
|
| 72 |
-
label="
|
| 73 |
-
choices=["
|
| 74 |
-
value="
|
| 75 |
)
|
| 76 |
-
forge_btn = gr.Button("🔥
|
| 77 |
|
| 78 |
-
with gr.Column():
|
| 79 |
-
output_display = gr.
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
forge_btn.click(
|
| 82 |
fn=manifest_agent,
|
| 83 |
inputs=[agent_name, agent_element, agent_focus],
|
| 84 |
outputs=output_display
|
| 85 |
)
|
| 86 |
-
|
| 87 |
-
gr.Markdown("---")
|
| 88 |
-
gr.Markdown("ℹ️ *Powered by Buddha-V2 Fine-Tuned Weights*")
|
| 89 |
|
| 90 |
if __name__ == "__main__":
|
| 91 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import torch
|
| 4 |
+
import json
|
| 5 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 6 |
|
| 7 |
+
# --- SOVEREIGN CONFIGURATION ---
|
| 8 |
+
# Replace this with your actual public wallet address
|
| 9 |
+
MY_SOVEREIGN_WALLET = "0xYourActualWalletAddressHere"
|
| 10 |
+
NETWORK = "Base (Layer 2)" # Low fees, high speed for your rails
|
| 11 |
+
|
| 12 |
MODEL_DIR = "./buddha_v2_model"
|
| 13 |
BASE_MODEL = "mistralai/Mistral-7B-v0.1"
|
| 14 |
|
| 15 |
+
def load_sovereign_brain():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
try:
|
| 17 |
path = MODEL_DIR if os.path.exists(MODEL_DIR) else BASE_MODEL
|
| 18 |
tokenizer = AutoTokenizer.from_pretrained(path)
|
|
|
|
| 20 |
path,
|
| 21 |
device_map="auto",
|
| 22 |
torch_dtype=torch.float16,
|
| 23 |
+
load_in_4bit=True
|
| 24 |
)
|
| 25 |
return pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 26 |
except Exception as e:
|
|
|
|
| 27 |
return None
|
| 28 |
|
| 29 |
+
generator = load_sovereign_brain()
|
|
|
|
| 30 |
|
| 31 |
def manifest_agent(name, element, focus):
|
| 32 |
"""
|
| 33 |
+
Manifests a Sovereign Agent.
|
| 34 |
+
The output now includes direct-to-wallet logic blueprints.
|
| 35 |
"""
|
| 36 |
+
prompt = f"""[INST] Role: Sovereign Agent Forge
|
| 37 |
+
Philosophy: No Middlemen, Direct-to-Wallet Rails, Total Autonomy.
|
| 38 |
Input Name: {name}
|
| 39 |
Input Element: {element}
|
| 40 |
Input Focus: {focus}
|
| 41 |
|
| 42 |
+
Generate a profile that includes:
|
| 43 |
+
1. Sovereign Mission Statement
|
| 44 |
+
2. Self-Custody Revenue Logic (Direct to {MY_SOVEREIGN_WALLET})
|
| 45 |
+
3. Autonomous Interaction Protocol
|
|
|
|
| 46 |
[/INST]"""
|
| 47 |
|
| 48 |
if generator:
|
| 49 |
+
response = generator(prompt, max_new_tokens=600, do_sample=True, temperature=0.6)
|
| 50 |
return response[0]['generated_text'].split("[/INST]")[-1].strip()
|
| 51 |
else:
|
| 52 |
+
return "Forge Calibrating... Sovereignty takes time to manifest. Ensure your fine-tuning script is running in the background."
|
|
|
|
| 53 |
|
| 54 |
+
# --- UI Layout ---
|
| 55 |
+
with gr.Blocks(theme=gr.themes.Monochrome()) as demo: # Clean, serious, sovereign look
|
| 56 |
+
gr.Markdown(f"# 🌌 Sovereign Star Magic Forge")
|
| 57 |
+
gr.Markdown(f"**Network:** {NETWORK} | **Settlement:** Direct-to-Wallet")
|
| 58 |
|
| 59 |
with gr.Row():
|
| 60 |
+
with gr.Column(scale=1):
|
| 61 |
+
agent_name = gr.Textbox(label="Agent Designation", placeholder="e.g., SOV-01")
|
| 62 |
+
agent_element = gr.Radio(
|
| 63 |
+
label="Primary Essence",
|
| 64 |
+
choices=["Void", "Solar", "Aether"],
|
| 65 |
value="Void"
|
| 66 |
)
|
| 67 |
+
agent_focus = gr.Dropdown(
|
| 68 |
+
label="Core Logic Focus",
|
| 69 |
+
choices=["Direct Revenue Architecture", "Security Penetration", "Autonomous Defense"],
|
| 70 |
+
value="Direct Revenue Architecture"
|
| 71 |
)
|
| 72 |
+
forge_btn = gr.Button("🔥 MANIFEST SOVEREIGN ENTITY", variant="primary")
|
| 73 |
|
| 74 |
+
with gr.Column(scale=2):
|
| 75 |
+
output_display = gr.Markdown(label="Sovereign Blueprint")
|
| 76 |
+
|
| 77 |
+
gr.Markdown(f"---")
|
| 78 |
+
gr.Markdown(f"🛡️ **Sovereignty Note:** This forge is hardcoded to settle directly to `{MY_SOVEREIGN_WALLET}`. No third-party processors are utilized.")
|
| 79 |
|
| 80 |
forge_btn.click(
|
| 81 |
fn=manifest_agent,
|
| 82 |
inputs=[agent_name, agent_element, agent_focus],
|
| 83 |
outputs=output_display
|
| 84 |
)
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
if __name__ == "__main__":
|
| 87 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|