Unfaithful commited on
Commit
dd42f9d
·
verified ·
1 Parent(s): ce90055

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -3,7 +3,6 @@ from transformers import pipeline
3
  import plotly.graph_objects as go
4
  import json
5
  import os
6
- import random
7
  import threading
8
  import time
9
 
@@ -14,6 +13,7 @@ DB_FILE = "fractal_tree.json"
14
  classification_model = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
15
  generation_model = pipeline("text-generation", model="gpt2", max_length=50, temperature=0.7)
16
 
 
17
  class Node:
18
  def __init__(self, node_id, data, module, parent_id=None):
19
  self.node_id = node_id
@@ -81,13 +81,22 @@ class FractalTree:
81
  return new_node
82
 
83
  def ai_expand_node(self, parent_node):
84
- """Use GPT-2 to generate intelligent node data."""
85
- prompt = f"Generate creative suggestions for a child node based on: {parent_node.data}"
86
- response = generation_model(prompt, num_return_sequences=3)
87
  suggestions = [res["generated_text"].strip() for res in response]
88
  for suggestion in suggestions:
89
  self.add_node(parent_node, suggestion)
90
 
 
 
 
 
 
 
 
 
 
91
  def auto_expand(self, iterations=1, children_per_node=2):
92
  """Automatically expand the tree iteratively."""
93
  for _ in range(iterations):
@@ -172,6 +181,11 @@ def add_custom_node(data):
172
  fractal_tree.add_node(fractal_tree.current_node, data)
173
  return f"Added custom node with data: {data}"
174
 
 
 
 
 
 
175
  def reset_tree():
176
  """Reset the entire fractal tree."""
177
  os.remove(DB_FILE) if os.path.exists(DB_FILE) else None
@@ -181,7 +195,7 @@ def reset_tree():
181
 
182
  # Gradio Interface
183
  with gr.Blocks() as app:
184
- gr.Markdown("# Fully AI-Powered Fractal Tree App with Plotly Visualizations")
185
 
186
  # Tree Visualization Section
187
  with gr.Row():
@@ -194,6 +208,11 @@ with gr.Blocks() as app:
194
  add_custom_node_button = gr.Button("Add Custom Node")
195
  add_custom_node_output = gr.Textbox(label="Output", interactive=False)
196
 
 
 
 
 
 
197
  # Automation Controls Section
198
  with gr.Row():
199
  automation_interval = gr.Number(label="Interval (seconds)", value=10, precision=0)
@@ -211,6 +230,7 @@ with gr.Blocks() as app:
211
  # Connect Functions
212
  tree_view_button.click(view_tree, outputs=[tree_view])
213
  add_custom_node_button.click(add_custom_node, inputs=[custom_node_input], outputs=[add_custom_node_output])
 
214
  start_automation_button.click(
215
  start_automation,
216
  inputs=[automation_interval, automation_iterations, automation_children],
 
3
  import plotly.graph_objects as go
4
  import json
5
  import os
 
6
  import threading
7
  import time
8
 
 
13
  classification_model = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
14
  generation_model = pipeline("text-generation", model="gpt2", max_length=50, temperature=0.7)
15
 
16
+
17
  class Node:
18
  def __init__(self, node_id, data, module, parent_id=None):
19
  self.node_id = node_id
 
81
  return new_node
82
 
83
  def ai_expand_node(self, parent_node):
84
+ """Generate intelligent node data using GPT-2."""
85
+ prompt = f"Generate creative and context-aware suggestions based on: {parent_node.data}"
86
+ response = generation_model(prompt, num_return_sequences=2)
87
  suggestions = [res["generated_text"].strip() for res in response]
88
  for suggestion in suggestions:
89
  self.add_node(parent_node, suggestion)
90
 
91
+ def emergent_behavior(self, parent_node):
92
+ """Apply emergent behaviors using intelligent inferences."""
93
+ prompt = f"What would be an interesting idea or extension of the topic: {parent_node.data}?"
94
+ response = generation_model(prompt, num_return_sequences=1)
95
+ emergent_data = response[0]["generated_text"].strip()
96
+
97
+ # Add emergent node
98
+ return self.add_node(parent_node, emergent_data)
99
+
100
  def auto_expand(self, iterations=1, children_per_node=2):
101
  """Automatically expand the tree iteratively."""
102
  for _ in range(iterations):
 
181
  fractal_tree.add_node(fractal_tree.current_node, data)
182
  return f"Added custom node with data: {data}"
183
 
184
+ def apply_emergent_behavior():
185
+ """Apply emergent behavior to the current node."""
186
+ result_node = fractal_tree.emergent_behavior(fractal_tree.current_node)
187
+ return f"Added emergent behavior node: {result_node.data}"
188
+
189
  def reset_tree():
190
  """Reset the entire fractal tree."""
191
  os.remove(DB_FILE) if os.path.exists(DB_FILE) else None
 
195
 
196
  # Gradio Interface
197
  with gr.Blocks() as app:
198
+ gr.Markdown("# Intelligent AI Fractal Tree with Emergent Behaviors")
199
 
200
  # Tree Visualization Section
201
  with gr.Row():
 
208
  add_custom_node_button = gr.Button("Add Custom Node")
209
  add_custom_node_output = gr.Textbox(label="Output", interactive=False)
210
 
211
+ # Emergent Behavior Section
212
+ with gr.Row():
213
+ emergent_behavior_button = gr.Button("Apply Emergent Behavior")
214
+ emergent_behavior_output = gr.Textbox(label="Emergent Behavior Status", interactive=False)
215
+
216
  # Automation Controls Section
217
  with gr.Row():
218
  automation_interval = gr.Number(label="Interval (seconds)", value=10, precision=0)
 
230
  # Connect Functions
231
  tree_view_button.click(view_tree, outputs=[tree_view])
232
  add_custom_node_button.click(add_custom_node, inputs=[custom_node_input], outputs=[add_custom_node_output])
233
+ emergent_behavior_button.click(apply_emergent_behavior, outputs=[emergent_behavior_output])
234
  start_automation_button.click(
235
  start_automation,
236
  inputs=[automation_interval, automation_iterations, automation_children],