Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files- components/SimulationGraph.tsx +115 -98
- components/SimulationPage.tsx +37 -1
- gradio_api.txt +129 -0
- services/gradioService.ts +33 -0
components/SimulationGraph.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import React, { useEffect, useRef, useState } from 'react';
|
| 2 |
import Plotly from 'plotly.js';
|
| 3 |
-
import { X, Linkedin, Globe, MapPin, User, Briefcase, Users } from 'lucide-react';
|
| 4 |
import Button from './ui/Button';
|
|
|
|
| 5 |
|
| 6 |
interface SimulationGraphProps {
|
| 7 |
isBuilding: boolean;
|
|
@@ -19,112 +20,128 @@ const SimulationGraph: React.FC<SimulationGraphProps> = ({ isBuilding, societyTy
|
|
| 19 |
}, [isBuilding]);
|
| 20 |
|
| 21 |
useEffect(() => {
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
location: ['New York, USA', 'London, UK', 'Berlin, DE', 'Paris, FR'][Math.floor(Math.random() * 4)]
|
| 41 |
-
});
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
// Create edges
|
| 45 |
-
const edgeX: (number | null)[] = [];
|
| 46 |
-
const edgeY: (number | null)[] = [];
|
| 47 |
-
|
| 48 |
-
for (let i = 0; i < N; i++) {
|
| 49 |
-
for (let j = i + 1; j < N; j++) {
|
| 50 |
-
const dx = nodes[i].x - nodes[j].x;
|
| 51 |
-
const dy = nodes[i].y - nodes[j].y;
|
| 52 |
-
const dist = Math.sqrt(dx * dx + dy * dy);
|
| 53 |
-
|
| 54 |
-
if (dist < radius) {
|
| 55 |
-
nodes[i].connections++;
|
| 56 |
-
nodes[j].connections++;
|
| 57 |
-
edgeX.push(nodes[i].x, nodes[j].x, null);
|
| 58 |
-
edgeY.push(nodes[i].y, nodes[j].y, null);
|
| 59 |
}
|
|
|
|
|
|
|
| 60 |
}
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
const nodeX = nodes.map(n => n.x);
|
| 64 |
-
const nodeY = nodes.map(n => n.y);
|
| 65 |
-
const nodeColor = nodes.map(n => n.connections);
|
| 66 |
-
|
| 67 |
-
// --- Plotly Config ---
|
| 68 |
-
const edgeTrace = {
|
| 69 |
-
x: edgeX,
|
| 70 |
-
y: edgeY,
|
| 71 |
-
mode: 'lines',
|
| 72 |
-
line: { width: 0.5, color: '#4b5563' },
|
| 73 |
-
hoverinfo: 'none',
|
| 74 |
-
type: 'scatter'
|
| 75 |
-
};
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
// @ts-ignore
|
| 111 |
-
Plotly.newPlot(graphDiv.current, [edgeTrace, nodeTrace], layout, config).then((gd) => {
|
| 112 |
// @ts-ignore
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
});
|
| 124 |
-
}
|
| 125 |
});
|
| 126 |
-
}
|
| 127 |
|
|
|
|
| 128 |
}, [isBuilding, societyType]);
|
| 129 |
|
| 130 |
return (
|
|
|
|
| 1 |
import React, { useEffect, useRef, useState } from 'react';
|
| 2 |
import Plotly from 'plotly.js';
|
| 3 |
+
import { X, Linkedin, Globe, MapPin, User, Briefcase, Users, Loader2 } from 'lucide-react';
|
| 4 |
import Button from './ui/Button';
|
| 5 |
+
import { GradioService } from '../services/gradioService';
|
| 6 |
|
| 7 |
interface SimulationGraphProps {
|
| 8 |
isBuilding: boolean;
|
|
|
|
| 20 |
}, [isBuilding]);
|
| 21 |
|
| 22 |
useEffect(() => {
|
| 23 |
+
const renderGraph = async () => {
|
| 24 |
+
if (!graphDiv.current || isBuilding) return;
|
| 25 |
+
|
| 26 |
+
let nodes: any[] = [];
|
| 27 |
+
let edges: any[] = [];
|
| 28 |
+
|
| 29 |
+
try {
|
| 30 |
+
// Attempt to fetch real network data
|
| 31 |
+
const networkData = await GradioService.getNetworkGraph(societyType);
|
| 32 |
+
if (networkData && networkData.nodes) {
|
| 33 |
+
nodes = networkData.nodes.map((n: any) => ({
|
| 34 |
+
...n,
|
| 35 |
+
x: n.x || Math.random(),
|
| 36 |
+
y: n.y || Math.random(),
|
| 37 |
+
role: n.name || n.id || 'Persona',
|
| 38 |
+
location: n.location || 'Unknown'
|
| 39 |
+
}));
|
| 40 |
+
edges = networkData.edges || [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
}
|
| 42 |
+
} catch (e) {
|
| 43 |
+
console.warn("Failed to fetch real network, falling back to mock.");
|
| 44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
// Fallback to mock data if no real data
|
| 47 |
+
if (nodes.length === 0) {
|
| 48 |
+
const safeSocietyType = typeof societyType === 'string' ? societyType : '';
|
| 49 |
+
const isTech = safeSocietyType.includes('Tech') || safeSocietyType.includes('Founders');
|
| 50 |
+
const N = isTech ? 120 : 80;
|
| 51 |
+
const radius = isTech ? 0.18 : 0.22;
|
| 52 |
+
|
| 53 |
+
for (let i = 0; i < N; i++) {
|
| 54 |
+
nodes.push({
|
| 55 |
+
x: Math.random(),
|
| 56 |
+
y: Math.random(),
|
| 57 |
+
connections: 0,
|
| 58 |
+
role: isTech ? ['Founder', 'CTO', 'Product Lead', 'VC'][Math.floor(Math.random() * 4)] : ['Journalist', 'Reader', 'Editor', 'Subscriber'][Math.floor(Math.random() * 4)],
|
| 59 |
+
location: ['New York, USA', 'London, UK', 'Berlin, DE', 'Paris, FR'][Math.floor(Math.random() * 4)]
|
| 60 |
+
});
|
| 61 |
+
}
|
| 62 |
|
| 63 |
+
for (let i = 0; i < N; i++) {
|
| 64 |
+
for (let j = i + 1; j < N; j++) {
|
| 65 |
+
const dx = nodes[i].x - nodes[j].x;
|
| 66 |
+
const dy = nodes[i].y - nodes[j].y;
|
| 67 |
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
| 68 |
+
if (dist < radius) {
|
| 69 |
+
nodes[i].connections++;
|
| 70 |
+
nodes[j].connections++;
|
| 71 |
+
edges.push({ source: i, target: j });
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
|
| 77 |
+
const edgeX: (number | null)[] = [];
|
| 78 |
+
const edgeY: (number | null)[] = [];
|
| 79 |
+
edges.forEach(edge => {
|
| 80 |
+
const source = nodes[edge.source];
|
| 81 |
+
const target = nodes[edge.target];
|
| 82 |
+
if (source && target) {
|
| 83 |
+
edgeX.push(source.x, target.x, null);
|
| 84 |
+
edgeY.push(source.y, target.y, null);
|
| 85 |
+
}
|
| 86 |
+
});
|
| 87 |
+
|
| 88 |
+
const nodeX = nodes.map(n => n.x);
|
| 89 |
+
const nodeY = nodes.map(n => n.y);
|
| 90 |
+
const nodeColor = nodes.map(n => n.connections || 0);
|
| 91 |
+
|
| 92 |
+
const edgeTrace = {
|
| 93 |
+
x: edgeX,
|
| 94 |
+
y: edgeY,
|
| 95 |
+
mode: 'lines',
|
| 96 |
+
line: { width: 0.5, color: '#4b5563' },
|
| 97 |
+
hoverinfo: 'none',
|
| 98 |
+
type: 'scatter'
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
const nodeTrace = {
|
| 102 |
+
x: nodeX,
|
| 103 |
+
y: nodeY,
|
| 104 |
+
mode: 'markers',
|
| 105 |
+
hoverinfo: 'none',
|
| 106 |
+
marker: {
|
| 107 |
+
showscale: false,
|
| 108 |
+
colorscale: 'Electric',
|
| 109 |
+
color: nodeColor,
|
| 110 |
+
size: 10,
|
| 111 |
+
line: { width: 0 }
|
| 112 |
+
},
|
| 113 |
+
type: 'scatter'
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
const layout = {
|
| 117 |
+
showlegend: false,
|
| 118 |
+
hovermode: 'closest',
|
| 119 |
+
margin: { b: 0, l: 0, r: 0, t: 0 },
|
| 120 |
+
xaxis: { showgrid: false, zeroline: false, showticklabels: false, range: [-0.05, 1.05], fixedrange: true },
|
| 121 |
+
yaxis: { showgrid: false, zeroline: false, showticklabels: false, range: [-0.05, 1.05], fixedrange: true },
|
| 122 |
+
paper_bgcolor: 'rgba(0,0,0,0)',
|
| 123 |
+
plot_bgcolor: 'rgba(0,0,0,0)',
|
| 124 |
+
autosize: true,
|
| 125 |
+
dragmode: false
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
const config = { staticPlot: false, displayModeBar: false, responsive: true };
|
| 129 |
|
|
|
|
|
|
|
| 130 |
// @ts-ignore
|
| 131 |
+
Plotly.newPlot(graphDiv.current, [edgeTrace, nodeTrace], layout, config).then((gd) => {
|
| 132 |
+
// @ts-ignore
|
| 133 |
+
gd.on('plotly_click', (data) => {
|
| 134 |
+
const point = data.points[0];
|
| 135 |
+
if (point) {
|
| 136 |
+
const nodeIndex = point.pointNumber;
|
| 137 |
+
const nodeData = nodes[nodeIndex];
|
| 138 |
+
setSelectedProfile({ x: point.x, y: point.y, data: nodeData });
|
| 139 |
+
}
|
| 140 |
+
});
|
|
|
|
|
|
|
| 141 |
});
|
| 142 |
+
};
|
| 143 |
|
| 144 |
+
renderGraph();
|
| 145 |
}, [isBuilding, societyType]);
|
| 146 |
|
| 147 |
return (
|
components/SimulationPage.tsx
CHANGED
|
@@ -439,7 +439,43 @@ const SimulationPage: React.FC<SimulationPageProps> = ({
|
|
| 439 |
</button>
|
| 440 |
<button
|
| 441 |
onClick={async () => {
|
| 442 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
try {
|
| 444 |
const response = await fetch('/api/save-data', {
|
| 445 |
method: 'POST',
|
|
|
|
| 439 |
</button>
|
| 440 |
<button
|
| 441 |
onClick={async () => {
|
| 442 |
+
if (activeModal === 'assemble') {
|
| 443 |
+
setIsBuilding(true);
|
| 444 |
+
try {
|
| 445 |
+
// 1. Generate personas based on profile and company info
|
| 446 |
+
const personas = await GradioService.generatePersonas(formData.companyInfo, formData.customerProfile, 5);
|
| 447 |
+
|
| 448 |
+
// 2. Generate social network for these personas
|
| 449 |
+
const groupName = formData.customerProfile.substring(0, 20);
|
| 450 |
+
await GradioService.generateSocialNetwork(groupName, 10, 'scale_free', groupName);
|
| 451 |
+
|
| 452 |
+
// 3. Save to backend
|
| 453 |
+
await fetch('/api/save-data', {
|
| 454 |
+
method: 'POST',
|
| 455 |
+
headers: { 'Content-Type': 'application/json' },
|
| 456 |
+
body: JSON.stringify({
|
| 457 |
+
type: 'assemble',
|
| 458 |
+
data: { ...formData, generatedPersonas: personas },
|
| 459 |
+
user: user?.preferred_username || 'anonymous'
|
| 460 |
+
})
|
| 461 |
+
});
|
| 462 |
+
|
| 463 |
+
// 4. Update UI
|
| 464 |
+
setSocieties(prev => [groupName, ...prev]);
|
| 465 |
+
setSociety(groupName);
|
| 466 |
+
setActiveModal('none');
|
| 467 |
+
alert('Focus group assembled and selected!');
|
| 468 |
+
} catch (e) {
|
| 469 |
+
console.error(e);
|
| 470 |
+
alert('Failed to assemble group via API. Falling back to local save.');
|
| 471 |
+
setActiveModal('none');
|
| 472 |
+
} finally {
|
| 473 |
+
setIsBuilding(false);
|
| 474 |
+
}
|
| 475 |
+
return;
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
// Save to backend logic for other modals
|
| 479 |
try {
|
| 480 |
const response = await fetch('/api/save-data', {
|
| 481 |
method: 'POST',
|
gradio_api.txt
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Loaded as API: https://auxteam-tiny-factory.hf.space
|
| 2 |
+
Client.predict() Usage Info
|
| 3 |
+
---------------------------
|
| 4 |
+
Named API endpoints: 18
|
| 5 |
+
|
| 6 |
+
- predict(business_description, customer_profile, num_personas, blablador_api_key, api_name="/generate_personas") -> output_generated_or_matched_persona
|
| 7 |
+
Parameters:
|
| 8 |
+
- [Textbox] business_description: str (required)
|
| 9 |
+
- [Textbox] customer_profile: str (required)
|
| 10 |
+
- [Number] num_personas: float (not required, defaults to: 1)
|
| 11 |
+
- [Textbox] blablador_api_key: str | None (not required, defaults to: None)
|
| 12 |
+
Returns:
|
| 13 |
+
- [Json] output_generated_or_matched_persona: str | float | bool | list | dict (any valid json)
|
| 14 |
+
|
| 15 |
+
- predict(criteria, api_name="/find_best_persona") -> output_generated_or_matched_persona
|
| 16 |
+
Parameters:
|
| 17 |
+
- [Textbox] criteria: str (required)
|
| 18 |
+
Returns:
|
| 19 |
+
- [Json] output_generated_or_matched_persona: str | float | bool | list | dict (any valid json)
|
| 20 |
+
|
| 21 |
+
- predict(context, api_name="/identify_personas") -> value_20
|
| 22 |
+
Parameters:
|
| 23 |
+
- [Textbox] context: str (required)
|
| 24 |
+
Returns:
|
| 25 |
+
- [Json] value_20: str | float | bool | list | dict (any valid json)
|
| 26 |
+
|
| 27 |
+
- predict(name, persona_count, network_type, focus_group_name, api_name="/generate_social_network") -> value_28
|
| 28 |
+
Parameters:
|
| 29 |
+
- [Textbox] name: str (required)
|
| 30 |
+
- [Number] persona_count: float (not required, defaults to: 10)
|
| 31 |
+
- [Dropdown] network_type: Literal['scale_free', 'small_world'] (not required, defaults to: scale_free)
|
| 32 |
+
- [Textbox] focus_group_name: str | None (not required, defaults to: None)
|
| 33 |
+
Returns:
|
| 34 |
+
- [Json] value_28: str | float | bool | list | dict (any valid json)
|
| 35 |
+
|
| 36 |
+
- predict(simulation_id, content_text, format, api_name="/predict_engagement") -> value_35
|
| 37 |
+
Parameters:
|
| 38 |
+
- [Textbox] simulation_id: str (required)
|
| 39 |
+
- [Textbox] content_text: str (required)
|
| 40 |
+
- [Textbox] format: str (not required, defaults to: text)
|
| 41 |
+
Returns:
|
| 42 |
+
- [Json] value_35: str | float | bool | list | dict (any valid json)
|
| 43 |
+
|
| 44 |
+
- predict(simulation_id, content_text, format, api_name="/start_simulation_async") -> value_42
|
| 45 |
+
Parameters:
|
| 46 |
+
- [Textbox] simulation_id: str (required)
|
| 47 |
+
- [Textbox] content_text: str (required)
|
| 48 |
+
- [Textbox] format: str (not required, defaults to: text)
|
| 49 |
+
Returns:
|
| 50 |
+
- [Json] value_42: str | float | bool | list | dict (any valid json)
|
| 51 |
+
|
| 52 |
+
- predict(simulation_id, api_name="/get_simulation_status") -> value_45
|
| 53 |
+
Parameters:
|
| 54 |
+
- [Textbox] simulation_id: str (required)
|
| 55 |
+
Returns:
|
| 56 |
+
- [Json] value_45: str | float | bool | list | dict (any valid json)
|
| 57 |
+
|
| 58 |
+
- predict(simulation_id, sender, message, api_name="/send_chat_message") -> value_53
|
| 59 |
+
Parameters:
|
| 60 |
+
- [Textbox] simulation_id: str (required)
|
| 61 |
+
- [Textbox] sender: str (not required, defaults to: User)
|
| 62 |
+
- [Textbox] message: str (required)
|
| 63 |
+
Returns:
|
| 64 |
+
- [Json] value_53: str | float | bool | list | dict (any valid json)
|
| 65 |
+
|
| 66 |
+
- predict(simulation_id, api_name="/get_chat_history") -> value_55
|
| 67 |
+
Parameters:
|
| 68 |
+
- [Textbox] simulation_id: str (required)
|
| 69 |
+
Returns:
|
| 70 |
+
- [Json] value_55: str | float | bool | list | dict (any valid json)
|
| 71 |
+
|
| 72 |
+
- predict(content_text, num_variants, api_name="/generate_variants") -> value_61
|
| 73 |
+
Parameters:
|
| 74 |
+
- [Textbox] content_text: str (required)
|
| 75 |
+
- [Number] num_variants: float (not required, defaults to: 5)
|
| 76 |
+
Returns:
|
| 77 |
+
- [Json] value_61: str | float | bool | list | dict (any valid json)
|
| 78 |
+
|
| 79 |
+
- predict(api_name="/list_simulations") -> value_65
|
| 80 |
+
Parameters:
|
| 81 |
+
- None
|
| 82 |
+
Returns:
|
| 83 |
+
- [Json] value_65: str | float | bool | list | dict (any valid json)
|
| 84 |
+
|
| 85 |
+
- predict(simulation_id, api_name="/list_personas") -> value_69
|
| 86 |
+
Parameters:
|
| 87 |
+
- [Textbox] simulation_id: str (required)
|
| 88 |
+
Returns:
|
| 89 |
+
- [Json] value_69: str | float | bool | list | dict (any valid json)
|
| 90 |
+
|
| 91 |
+
- predict(simulation_id, persona_name, api_name="/get_persona") -> value_75
|
| 92 |
+
Parameters:
|
| 93 |
+
- [Textbox] simulation_id: str (required)
|
| 94 |
+
- [Textbox] persona_name: str (required)
|
| 95 |
+
Returns:
|
| 96 |
+
- [Json] value_75: str | float | bool | list | dict (any valid json)
|
| 97 |
+
|
| 98 |
+
- predict(simulation_id, api_name="/delete_simulation") -> value_80
|
| 99 |
+
Parameters:
|
| 100 |
+
- [Textbox] simulation_id: str (required)
|
| 101 |
+
Returns:
|
| 102 |
+
- [Json] value_80: str | float | bool | list | dict (any valid json)
|
| 103 |
+
|
| 104 |
+
- predict(simulation_id, api_name="/export_simulation") -> value_85
|
| 105 |
+
Parameters:
|
| 106 |
+
- [Textbox] simulation_id: str (required)
|
| 107 |
+
Returns:
|
| 108 |
+
- [Json] value_85: str | float | bool | list | dict (any valid json)
|
| 109 |
+
|
| 110 |
+
- predict(simulation_id, api_name="/get_network_graph") -> value_90
|
| 111 |
+
Parameters:
|
| 112 |
+
- [Textbox] simulation_id: str (required)
|
| 113 |
+
Returns:
|
| 114 |
+
- [Json] value_90: str | float | bool | list | dict (any valid json)
|
| 115 |
+
|
| 116 |
+
- predict(api_name="/list_focus_groups") -> value_94
|
| 117 |
+
Parameters:
|
| 118 |
+
- None
|
| 119 |
+
Returns:
|
| 120 |
+
- [Json] value_94: str | float | bool | list | dict (any valid json)
|
| 121 |
+
|
| 122 |
+
- predict(name, simulation_id, api_name="/save_focus_group") -> value_98
|
| 123 |
+
Parameters:
|
| 124 |
+
- [Textbox] name: str (required)
|
| 125 |
+
- [Textbox] simulation_id: str (required)
|
| 126 |
+
Returns:
|
| 127 |
+
- [Json] value_98: str | float | bool | list | dict (any valid json)
|
| 128 |
+
|
| 129 |
+
None
|
services/gradioService.ts
CHANGED
|
@@ -66,4 +66,37 @@ export class GradioService {
|
|
| 66 |
return [];
|
| 67 |
}
|
| 68 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
}
|
|
|
|
| 66 |
return [];
|
| 67 |
}
|
| 68 |
}
|
| 69 |
+
|
| 70 |
+
static async generatePersonas(businessDescription: string, customerProfile: string, numPersonas: number = 1) {
|
| 71 |
+
try {
|
| 72 |
+
const client = await this.getClient();
|
| 73 |
+
const result = await client.predict("/generate_personas", [businessDescription, customerProfile, numPersonas, null]);
|
| 74 |
+
return result.data[0];
|
| 75 |
+
} catch (error) {
|
| 76 |
+
console.error("Error generating personas:", error);
|
| 77 |
+
throw error;
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
static async generateSocialNetwork(name: string, personaCount: number = 10, networkType: string = "scale_free", focusGroupName: string | null = null) {
|
| 82 |
+
try {
|
| 83 |
+
const client = await this.getClient();
|
| 84 |
+
const result = await client.predict("/generate_social_network", [name, personaCount, networkType, focusGroupName]);
|
| 85 |
+
return result.data[0];
|
| 86 |
+
} catch (error) {
|
| 87 |
+
console.error("Error generating social network:", error);
|
| 88 |
+
throw error;
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
static async getNetworkGraph(simulationId: string) {
|
| 93 |
+
try {
|
| 94 |
+
const client = await this.getClient();
|
| 95 |
+
const result = await client.predict("/get_network_graph", [simulationId]);
|
| 96 |
+
return result.data[0];
|
| 97 |
+
} catch (error) {
|
| 98 |
+
console.error("Error getting network graph:", error);
|
| 99 |
+
throw error;
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
}
|