add modal to see code
Browse files- src/App.tsx +7 -0
- src/components/ModelCode.tsx +115 -0
- src/components/Sidebar.tsx +20 -9
src/App.tsx
CHANGED
@@ -12,10 +12,12 @@ import Sidebar from './components/Sidebar'
|
|
12 |
import ModelReadme from './components/ModelReadme'
|
13 |
import { PipelineLayout } from './components/PipelineLayout'
|
14 |
import Footer from './Footer'
|
|
|
15 |
|
16 |
function App() {
|
17 |
const [isSidebarOpen, setIsSidebarOpen] = useState(false)
|
18 |
const [isModalOpen, setIsModalOpen] = useState(false)
|
|
|
19 |
const { pipeline, setModels, setModelInfo, modelInfo, setIsFetching } =
|
20 |
useModel()
|
21 |
|
@@ -74,6 +76,11 @@ function App() {
|
|
74 |
isOpen={isSidebarOpen}
|
75 |
onClose={() => setIsSidebarOpen(false)}
|
76 |
setIsModalOpen={setIsModalOpen}
|
|
|
|
|
|
|
|
|
|
|
77 |
/>
|
78 |
</div>
|
79 |
</PipelineLayout>
|
|
|
12 |
import ModelReadme from './components/ModelReadme'
|
13 |
import { PipelineLayout } from './components/PipelineLayout'
|
14 |
import Footer from './Footer'
|
15 |
+
import ModelCode from './components/ModelCode'
|
16 |
|
17 |
function App() {
|
18 |
const [isSidebarOpen, setIsSidebarOpen] = useState(false)
|
19 |
const [isModalOpen, setIsModalOpen] = useState(false)
|
20 |
+
const [isCodeModalOpen, setIsCodeModalOpen] = useState(false)
|
21 |
const { pipeline, setModels, setModelInfo, modelInfo, setIsFetching } =
|
22 |
useModel()
|
23 |
|
|
|
76 |
isOpen={isSidebarOpen}
|
77 |
onClose={() => setIsSidebarOpen(false)}
|
78 |
setIsModalOpen={setIsModalOpen}
|
79 |
+
setIsCodeModalOpen={setIsCodeModalOpen}
|
80 |
+
/>
|
81 |
+
<ModelCode
|
82 |
+
isCodeModalOpen={isCodeModalOpen}
|
83 |
+
setIsCodeModalOpen={setIsCodeModalOpen}
|
84 |
/>
|
85 |
</div>
|
86 |
</PipelineLayout>
|
src/components/ModelCode.tsx
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { ExternalLink } from 'lucide-react'
|
2 |
+
import Modal from './Modal'
|
3 |
+
import MarkdownRenderer from './MarkdownRenderer'
|
4 |
+
import { useModel } from '@/contexts/ModelContext'
|
5 |
+
import { useTextGeneration } from '@/contexts/TextGenerationContext'
|
6 |
+
|
7 |
+
interface ModelCodeProps {
|
8 |
+
isCodeModalOpen: boolean
|
9 |
+
setIsCodeModalOpen: (isOpen: boolean) => void
|
10 |
+
}
|
11 |
+
|
12 |
+
const ModelCode = ({ isCodeModalOpen, setIsCodeModalOpen }: ModelCodeProps) => {
|
13 |
+
const { modelInfo, pipeline, selectedQuantization } = useModel()
|
14 |
+
if (!modelInfo) return null
|
15 |
+
|
16 |
+
const title = (
|
17 |
+
<div className="flex items-center space-x-2">
|
18 |
+
<a
|
19 |
+
className="truncate hover:underline"
|
20 |
+
href={`https://huggingface.co/${modelInfo.name}`}
|
21 |
+
target="_blank"
|
22 |
+
rel="noopener noreferrer"
|
23 |
+
>
|
24 |
+
<ExternalLink className="w-3 h-3 inline-block mr-1" />
|
25 |
+
|
26 |
+
{modelInfo.name}
|
27 |
+
</a>
|
28 |
+
</div>
|
29 |
+
)
|
30 |
+
|
31 |
+
let classType = 'classifier'
|
32 |
+
let exampleData = 'I love this product!'
|
33 |
+
let config = {}
|
34 |
+
switch (pipeline) {
|
35 |
+
case 'text-classification':
|
36 |
+
classType = 'classifier'
|
37 |
+
exampleData = 'I love this product!'
|
38 |
+
config = {}
|
39 |
+
break
|
40 |
+
case 'text-generation':
|
41 |
+
classType = 'generator'
|
42 |
+
exampleData = 'I love this product!'
|
43 |
+
config = {
|
44 |
+
max_length: 50,
|
45 |
+
do_sample: true,
|
46 |
+
temperature: 0.7,
|
47 |
+
top_p: 0.9,
|
48 |
+
top_k: 50
|
49 |
+
}
|
50 |
+
break
|
51 |
+
|
52 |
+
case 'zero-shot-classification':
|
53 |
+
classType = 'classifier'
|
54 |
+
exampleData = "I love this product!, ['positive', 'neutral', 'negative']"
|
55 |
+
config = {
|
56 |
+
threshold: 0.5
|
57 |
+
}
|
58 |
+
break
|
59 |
+
case 'feature-extraction':
|
60 |
+
classType = 'generator'
|
61 |
+
exampleData = 'I love this product!'
|
62 |
+
config = {
|
63 |
+
pooling: 'mean',
|
64 |
+
normalize: true
|
65 |
+
}
|
66 |
+
break
|
67 |
+
case 'image-classification':
|
68 |
+
classType = 'classifier'
|
69 |
+
exampleData = 'https://example.com/image.jpg'
|
70 |
+
config = {
|
71 |
+
top_k: 5
|
72 |
+
}
|
73 |
+
break
|
74 |
+
}
|
75 |
+
|
76 |
+
const code = `import { pipeline } from '@huggingface/transformers';
|
77 |
+
|
78 |
+
const ${classType} = pipeline('${pipeline}', '${modelInfo.name}', {
|
79 |
+
dtype: '${selectedQuantization}',
|
80 |
+
device: 'webgpu' // 'wasm'
|
81 |
+
});
|
82 |
+
const result = await ${classType}('${exampleData}', ${JSON.stringify(config, null, 2)});
|
83 |
+
console.log(result);
|
84 |
+
`
|
85 |
+
|
86 |
+
console.log(modelInfo.widgetData)
|
87 |
+
|
88 |
+
return (
|
89 |
+
<>
|
90 |
+
<Modal
|
91 |
+
isOpen={isCodeModalOpen}
|
92 |
+
onClose={() => setIsCodeModalOpen(false)}
|
93 |
+
title={title}
|
94 |
+
maxWidth="5xl"
|
95 |
+
>
|
96 |
+
<div className="text-sm max-w-none px-4">
|
97 |
+
<MarkdownRenderer content={`\`\`\`typescript\n${code}\n\`\`\``} />
|
98 |
+
</div>
|
99 |
+
{/* More information link */}
|
100 |
+
<div className="mt-4">
|
101 |
+
<a
|
102 |
+
className="text-blue-500 hover:underline"
|
103 |
+
href={`https://huggingface.co/${modelInfo.name}`}
|
104 |
+
target="_blank"
|
105 |
+
rel="noopener noreferrer"
|
106 |
+
>
|
107 |
+
Learn more about this model on Hugging Face
|
108 |
+
</a>
|
109 |
+
</div>
|
110 |
+
</Modal>
|
111 |
+
</>
|
112 |
+
)
|
113 |
+
}
|
114 |
+
|
115 |
+
export default ModelCode
|
src/components/Sidebar.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { FileText, X } from 'lucide-react'
|
2 |
import PipelineSelector from './PipelineSelector'
|
3 |
import ModelSelector from './ModelSelector'
|
4 |
import ModelInfo from './ModelInfo'
|
@@ -7,14 +7,21 @@ import TextGenerationConfig from './pipelines/TextGenerationConfig'
|
|
7 |
import FeatureExtractionConfig from './pipelines/FeatureExtractionConfig'
|
8 |
import ZeroShotClassificationConfig from './pipelines/ZeroShotClassificationConfig'
|
9 |
import ImageClassificationConfig from './pipelines/ImageClassificationConfig'
|
|
|
10 |
|
11 |
interface SidebarProps {
|
12 |
isOpen: boolean
|
13 |
onClose: () => void
|
14 |
setIsModalOpen: (isOpen: boolean) => void
|
|
|
15 |
}
|
16 |
|
17 |
-
const Sidebar = ({
|
|
|
|
|
|
|
|
|
|
|
18 |
const { pipeline, setPipeline } = useModel()
|
19 |
|
20 |
return (
|
@@ -71,14 +78,18 @@ const Sidebar = ({ isOpen, onClose, setIsModalOpen }: SidebarProps) => {
|
|
71 |
<div className="flex flex-col items-center justify-center">
|
72 |
<ModelInfo />
|
73 |
{/* Model README Button */}
|
74 |
-
<div className="
|
75 |
-
<
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
78 |
>
|
79 |
-
<
|
80 |
-
<span
|
81 |
-
</
|
82 |
</div>
|
83 |
</div>
|
84 |
|
|
|
1 |
+
import { Code2, FileText, X } from 'lucide-react'
|
2 |
import PipelineSelector from './PipelineSelector'
|
3 |
import ModelSelector from './ModelSelector'
|
4 |
import ModelInfo from './ModelInfo'
|
|
|
7 |
import FeatureExtractionConfig from './pipelines/FeatureExtractionConfig'
|
8 |
import ZeroShotClassificationConfig from './pipelines/ZeroShotClassificationConfig'
|
9 |
import ImageClassificationConfig from './pipelines/ImageClassificationConfig'
|
10 |
+
import { Button } from '@/components/ui/button'
|
11 |
|
12 |
interface SidebarProps {
|
13 |
isOpen: boolean
|
14 |
onClose: () => void
|
15 |
setIsModalOpen: (isOpen: boolean) => void
|
16 |
+
setIsCodeModalOpen: (isOpen: boolean) => void
|
17 |
}
|
18 |
|
19 |
+
const Sidebar = ({
|
20 |
+
isOpen,
|
21 |
+
onClose,
|
22 |
+
setIsModalOpen,
|
23 |
+
setIsCodeModalOpen
|
24 |
+
}: SidebarProps) => {
|
25 |
const { pipeline, setPipeline } = useModel()
|
26 |
|
27 |
return (
|
|
|
78 |
<div className="flex flex-col items-center justify-center">
|
79 |
<ModelInfo />
|
80 |
{/* Model README Button */}
|
81 |
+
<div className="flex flex-row mt-2 space-x-4 ">
|
82 |
+
<Button variant="outline" onClick={() => setIsModalOpen(true)}>
|
83 |
+
<FileText className="w-4 h-4 flex-shrink-0" />
|
84 |
+
<span>View README.md</span>
|
85 |
+
</Button>
|
86 |
+
<Button
|
87 |
+
variant="outline"
|
88 |
+
onClick={() => setIsCodeModalOpen(true)}
|
89 |
>
|
90 |
+
<Code2 className="w-4 h-4 flex-shrink-0" />
|
91 |
+
<span>See Code</span>
|
92 |
+
</Button>
|
93 |
</div>
|
94 |
</div>
|
95 |
|