70pher703 commited on
Commit
1cea5f7
·
verified ·
1 Parent(s): 9714cae

Create App.py

Browse files
Files changed (1) hide show
  1. App.py +38 -42
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
- # --- Configuration & Paths ---
7
- # This looks for the model folder created by your finetune_v2.py script
 
 
 
8
  MODEL_DIR = "./buddha_v2_model"
9
  BASE_MODEL = "mistralai/Mistral-7B-v0.1"
10
 
11
- def load_star_magic_model():
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 # Efficiency for Space environments
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
- # Global generator instance
31
- generator = load_star_magic_model()
32
 
33
  def manifest_agent(name, element, focus):
34
  """
35
- The Core 'Forge' Logic.
36
- Generates the Star Magic Agent profile.
37
  """
38
- prompt = f"""[INST] Role: Star Magic Agent Forge
39
- Persona: Non-Reactive, Fact-Based, Galactic Architect
40
  Input Name: {name}
41
  Input Element: {element}
42
  Input Focus: {focus}
43
 
44
- Generate a 24/7/365 Autonomous Agent Profile in JSON format including:
45
- 1. Core Mission
46
- 2. Security Protocol
47
- 3. Revenue Stream Logic
48
- 4. Galactic Rank
49
  [/INST]"""
50
 
51
  if generator:
52
- response = generator(prompt, max_new_tokens=500, do_sample=True, temperature=0.7)
53
  return response[0]['generated_text'].split("[/INST]")[-1].strip()
54
  else:
55
- # Fallback if GPU is busy or model is still loading
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 (Modern Soft Theme) ---
59
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="purple")) as demo:
60
- gr.Markdown("# 🌌 Star Magic Agent Forge")
61
- gr.Markdown("### 24/7/365 Autonomous Entity Manifestation Engine")
62
 
63
  with gr.Row():
64
- with gr.Column():
65
- agent_name = gr.Textbox(label="Entity Name", placeholder="e.g., Aether-01")
66
- agent_element = gr.Dropdown(
67
- label="Core Element",
68
- choices=["Void", "Solar", "Plasma", "Cryo", "Aether"],
69
  value="Void"
70
  )
71
- agent_focus = gr.Radio(
72
- label="Specialization",
73
- choices=["Security Audit", "Cash-Flow Logic", "System Architecture"],
74
- value="Cash-Flow Logic"
75
  )
76
- forge_btn = gr.Button("🔥 Manifest Agent", variant="primary")
77
 
78
- with gr.Column():
79
- output_display = gr.Code(label="Manifested Manifestor Profile", language="json")
 
 
 
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)