cryogenic22 commited on
Commit
1296dc3
·
verified ·
1 Parent(s): 232470c

Create static/app.js

Browse files
Files changed (1) hide show
  1. static/app.js +117 -0
static/app.js ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const { useState } = React;
2
+ const { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer } = Recharts;
3
+
4
+ function App() {
5
+ const [data, setData] = useState(null);
6
+ const [query, setQuery] = useState('');
7
+ const [insights, setInsights] = useState([]);
8
+
9
+ const handleFileUpload = async (event) => {
10
+ const file = event.target.files[0];
11
+ const formData = new FormData();
12
+ formData.append('file', file);
13
+
14
+ const response = await fetch('/api/process-file', {
15
+ method: 'POST',
16
+ body: formData,
17
+ });
18
+ const result = await response.json();
19
+ setData(result);
20
+ };
21
+
22
+ const handleQuery = async () => {
23
+ if (!data || !query) return;
24
+
25
+ const response = await fetch('/api/query', {
26
+ method: 'POST',
27
+ headers: { 'Content-Type': 'application/json' },
28
+ body: JSON.stringify({
29
+ query,
30
+ embeddings: data.embeddings
31
+ }),
32
+ });
33
+
34
+ const result = await response.json();
35
+ const newInsights = result.similar_indices.map(idx => data.raw_data[idx]);
36
+ setInsights(newInsights);
37
+ };
38
+
39
+ return (
40
+ <div className="p-6 max-w-6xl mx-auto">
41
+ <div className="mb-6">
42
+ <label className="block mb-2 text-sm font-medium">
43
+ Upload Data File
44
+ </label>
45
+ <div className="flex items-center justify-center w-full">
46
+ <label className="flex flex-col items-center justify-center w-full h-32 border-2 border-dashed rounded-lg cursor-pointer bg-gray-50 hover:bg-gray-100">
47
+ <div className="flex flex-col items-center justify-center pt-5 pb-6">
48
+ <svg className="w-8 h-8 mb-4 text-gray-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 16">
49
+ <path stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"/>
50
+ </svg>
51
+ <p className="mb-2 text-sm text-gray-500">
52
+ <span className="font-semibold">Click to upload</span> or drag and drop
53
+ </p>
54
+ </div>
55
+ <input
56
+ type="file"
57
+ className="hidden"
58
+ onChange={handleFileUpload}
59
+ accept=".csv,.xlsx,.xls"
60
+ />
61
+ </label>
62
+ </div>
63
+ </div>
64
+
65
+ {data && (
66
+ <div className="space-y-6">
67
+ <div>
68
+ <input
69
+ type="text"
70
+ value={query}
71
+ onChange={(e) => setQuery(e.target.value)}
72
+ placeholder="Ask a question about your data..."
73
+ className="w-full p-2 border rounded"
74
+ />
75
+ <button
76
+ onClick={handleQuery}
77
+ className="mt-2 px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700"
78
+ >
79
+ Search
80
+ </button>
81
+ </div>
82
+
83
+ {insights.length > 0 && (
84
+ <div className="mt-6">
85
+ <h3 className="text-lg font-semibold mb-4">Related Insights</h3>
86
+ <div className="h-64">
87
+ <ResponsiveContainer width="100%" height="100%">
88
+ <BarChart data={insights}>
89
+ {Object.keys(insights[0] || {}).map((key) => (
90
+ <Bar key={key} dataKey={key} fill="#8884d8" />
91
+ ))}
92
+ <XAxis />
93
+ <YAxis />
94
+ <Tooltip />
95
+ </BarChart>
96
+ </ResponsiveContainer>
97
+ </div>
98
+ <div className="mt-4 space-y-2">
99
+ {insights.map((insight, idx) => (
100
+ <div key={idx} className="p-4 bg-gray-50 rounded">
101
+ {Object.entries(insight).map(([key, value]) => (
102
+ <div key={key}>
103
+ <span className="font-medium">{key}:</span> {value}
104
+ </div>
105
+ ))}
106
+ </div>
107
+ ))}
108
+ </div>
109
+ </div>
110
+ )}
111
+ </div>
112
+ )}
113
+ </div>
114
+ );
115
+ }
116
+
117
+ ReactDOM.render(<App />, document.getElementById('root'));