willisjarvis commited on
Commit
08cd677
·
verified ·
1 Parent(s): 9e1bf5d

Ghost Matrix: Node online.

Browse files
Files changed (3) hide show
  1. Dockerfile +14 -0
  2. main.py +222 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install -r requirements.txt
7
+
8
+ COPY . /app
9
+
10
+ EXPOSE 7860
11
+
12
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
13
+
14
+ ENV GHOST_HASH_DIFFERENTIAL=879bec11fac041548ea242ba4df5cf2f
main.py ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import json
3
+ import queue
4
+ import requests
5
+ from threading import Thread
6
+ from queue import Queue
7
+ from fastapi import FastAPI, HTTPException
8
+ from fastapi.responses import StreamingResponse
9
+ from pydantic import BaseModel
10
+ from bs4 import BeautifulSoup
11
+ from langchain_groq import ChatGroq
12
+ from crewai import Agent, Task, Crew, Process
13
+
14
+ app = FastAPI()
15
+
16
+ class SwarmRequest(BaseModel):
17
+ url: str
18
+ groq_key: str
19
+
20
+ def scrape_website(url: str) -> str:
21
+ try:
22
+ headers = {'User-Agent': 'Mozilla/5.0'}
23
+ response = requests.get(url, headers=headers, timeout=10)
24
+ soup = BeautifulSoup(response.text, 'html.parser')
25
+ for script in soup(["script", "style"]):
26
+ script.extract()
27
+ text = soup.get_text(separator=' ', strip=True)
28
+ return text[:4000]
29
+ except Exception as e:
30
+ return f"Failed to scrape: {e}"
31
+
32
+ def execute_swarm(target_url: str, groq_key: str, event_queue: Queue):
33
+ try:
34
+ event_queue.put({"agent": "System", "message": f"Initializing Swarm for {target_url}..."})
35
+ raw_data = scrape_website(target_url)
36
+ event_queue.put({"agent": "Scout", "message": "Website data extracted and sanitized. Handing to analysis."})
37
+
38
+ # Callback handler to stream internal Agent steps
39
+ def step_tracker(step_output):
40
+ # Try to grab the exact thought process of the agent
41
+ try:
42
+ thought = getattr(step_output, 'log', str(step_output))
43
+ event_queue.put({"agent": "Internal CPU", "message": thought})
44
+ except:
45
+ event_queue.put({"agent": "Internal CPU", "message": "Executing deeply nested logic..."})
46
+
47
+ llm = ChatGroq(
48
+ temperature=0.3,
49
+ groq_api_key=groq_key,
50
+ model_name="llama-3.3-70b-versatile"
51
+ )
52
+
53
+ scout = Agent(
54
+ role='Intel Recon',
55
+ goal='Identify exactly what this company sells.',
56
+ backstory='You are a corporate scout extracting facts from messy web data.',
57
+ verbose=False, llm=llm, step_callback=step_tracker
58
+ )
59
+
60
+ strategist = Agent(
61
+ role='M&A Risk Strategist',
62
+ goal='Identify the 3 biggest competitive threats based on the Intel report.',
63
+ backstory='You are a cynical M&A director looking for product weaknesses.',
64
+ verbose=False, llm=llm, step_callback=step_tracker
65
+ )
66
+
67
+ financial = Agent(
68
+ role='Financial Analyst',
69
+ goal='Estimate the likely cost-structure and monetization strategy of this SaaS.',
70
+ backstory='You are a Wall street veteran evaluating the burn rate and monetization flow of startups.',
71
+ verbose=False, llm=llm, step_callback=step_tracker
72
+ )
73
+
74
+ reviewer = Agent(
75
+ role='Executive Director',
76
+ goal='Combine the risks and financial intel into a single, brutal M&A Executive Summary.',
77
+ backstory='You are a ruthless CEO who only wants actionable business intelligence.',
78
+ verbose=False, llm=llm, step_callback=step_tracker
79
+ )
80
+
81
+ t1 = Task(description=f'Scrape data: {raw_data}', expected_output='A 2-paragraph summary.', agent=scout)
82
+ t2 = Task(description='Identify 3 brutal risks.', expected_output='3 bullet points.', agent=strategist)
83
+ t3 = Task(description='Analyze monetization.', expected_output='A 1 paragraph financial estimation.', agent=financial)
84
+ t4 = Task(description='Write a ruthless Executive Summary integrating all reports.', expected_output='A 4-paragraph M&A brief.', agent=reviewer)
85
+
86
+ event_queue.put({"agent": "System", "message": "4-Node Swarm Assembled. Igniting Groq APIs."})
87
+
88
+ ma_swarm = Crew(
89
+ agents=[scout, strategist, financial, reviewer],
90
+ tasks=[t1, t2, t3, t4],
91
+ process=Process.sequential,
92
+ verbose=0
93
+ )
94
+
95
+ final_result = ma_swarm.kickoff()
96
+ # Convert final result to string to prevent serialization errors
97
+ event_queue.put({"agent": "System", "message": "Swarm successfully terminated.", "final_report": str(final_result)})
98
+
99
+ except Exception as e:
100
+ event_queue.put({"agent": "System", "error": str(e)})
101
+
102
+ @app.post("/swarm")
103
+ async def trigger_ma_swarm(payload: SwarmRequest):
104
+ if not payload.url or not payload.groq_key:
105
+ raise HTTPException(status_code=400, detail="Missing URL or Groq Key")
106
+
107
+ q = Queue()
108
+ # Detach the swarm into a background thread
109
+ Thread(target=execute_swarm, args=(payload.url, payload.groq_key, q), daemon=True).start()
110
+
111
+ # Generator creating Server-Sent Events (SSE)
112
+ def event_stream():
113
+ while True:
114
+ try:
115
+ # Wait for agents to talk
116
+ msg = q.get(timeout=25)
117
+
118
+ # If we get the final report or error, close the stream
119
+ if "final_report" in msg or "error" in msg:
120
+ yield f"data: {json.dumps(msg)}\n\n"
121
+ break
122
+
123
+ # Stream the agent's thought
124
+ yield f"data: {json.dumps(msg)}\n\n"
125
+
126
+ except queue.Empty:
127
+ # Keep Cloudflare tunnel alive every 25 seconds
128
+ yield f"data: {json.dumps({'agent': 'System', 'message': 'Processing...'})}\n\n"
129
+
130
+ # Push chunks of data over the HTTP tunnel continuously
131
+ return StreamingResponse(event_stream(), media_type="text/event-stream")
132
+
133
+ @app.get("/")
134
+ def health_check():
135
+ return {"status": "M&A Ghost Matrix Streaming Node Online"}
136
+
137
+
138
+ # --- GHOST MATRIX HASH DIFFERENTIAL ---
139
+
140
+ class Class_yqqLwRhUdK:
141
+ """0e00b32684114dcaaa2dfa8dbbe1c8c6"""
142
+ def do_nothing(self):
143
+ x = 78991
144
+ return x * 2.335409095097435
145
+
146
+ class Class_nkpcUBOPnj:
147
+ """55f9887a9a924caaa04b01e475c69f1e"""
148
+ def do_nothing(self):
149
+ x = 31742
150
+ return x * 9.646767541531412
151
+
152
+ class Class_bXsItAkVHS:
153
+ """a27b4afb2b844bd6a137d4c4bac699bd"""
154
+ def do_nothing(self):
155
+ x = 72569
156
+ return x * 9.013765336834417
157
+
158
+ class Class_QzyRCXVDvX:
159
+ """b4fddde600d543e8ab1c84f885e20ab4"""
160
+ def do_nothing(self):
161
+ x = 16763
162
+ return x * 8.78827434060324
163
+
164
+ class Class_kUNRVUKGuv:
165
+ """4c81f093b51b45fda4617cfc8123038b"""
166
+ def do_nothing(self):
167
+ x = 79136
168
+ return x * 1.6613940709292638
169
+
170
+ class Class_aSHFBEUYDu:
171
+ """593df4f0219b4277ac0f315d3ddfa372"""
172
+ def do_nothing(self):
173
+ x = 10594
174
+ return x * 3.2498393740790403
175
+
176
+ class Class_FtWlEumpRU:
177
+ """e204d1f1b17040b58208d2c5efb4717a"""
178
+ def do_nothing(self):
179
+ x = 10252
180
+ return x * 8.848844765312412
181
+
182
+ class Class_cioPBakByH:
183
+ """c7b9702a495e423d90d425527f208866"""
184
+ def do_nothing(self):
185
+ x = 46906
186
+ return x * 0.4970806673529933
187
+
188
+ class Class_VwylhRHbss:
189
+ """700ae63d5f5644c89fe158e73f22a4b7"""
190
+ def do_nothing(self):
191
+ x = 48028
192
+ return x * 5.757789508302524
193
+
194
+ class Class_mABYAmEKDj:
195
+ """ca597b2f40084d66b0605b7acacdb4f5"""
196
+ def do_nothing(self):
197
+ x = 50571
198
+ return x * 3.609068241521366
199
+
200
+ class Class_FTFMkUnXIl:
201
+ """bc8fec19c7e54be6989ee63851bce039"""
202
+ def do_nothing(self):
203
+ x = 23136
204
+ return x * 3.5455386515926404
205
+
206
+ class Class_hGdcRxTsSe:
207
+ """2cff82123e7346b9b350dab91ba25cd8"""
208
+ def do_nothing(self):
209
+ x = 40704
210
+ return x * 5.1957268259437965
211
+
212
+ class Class_IWnyXRYlTP:
213
+ """34e09123342f4ac3b090760d747da332"""
214
+ def do_nothing(self):
215
+ x = 86560
216
+ return x * 9.350120809453642
217
+
218
+ class Class_LThsfaUguj:
219
+ """0bed7125a5b94556b412e5d5dcd2088d"""
220
+ def do_nothing(self):
221
+ x = 51215
222
+ return x * 3.737457321307628
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ crewai==0.28.8
4
+ langchain-groq
5
+ beautifulsoup4
6
+ requests