Spaces:
Configuration error
Configuration error
zack
commited on
Commit
·
030e997
1
Parent(s):
a96854e
chore: remove src/components/Modal/importer.js 🧹
Browse files
frontend/src/components/Modal/importer.js
DELETED
@@ -1,198 +0,0 @@
|
|
1 |
-
import { Modal, Icon, Message} from 'semantic-ui-react'
|
2 |
-
import "../../css/dist/output.css"
|
3 |
-
import {ReactComponent as Gradio} from '../../images/gradio.svg'
|
4 |
-
import {ReactComponent as Streamlit} from '../../images/streamlit.svg'
|
5 |
-
import {ReactComponent as Exit} from '../../images/exit.svg'
|
6 |
-
import { useState } from 'react'
|
7 |
-
import {BsSearch} from 'react-icons/bs';
|
8 |
-
|
9 |
-
export default function Import(props){
|
10 |
-
const [tab, setTab] = useState("gradio")
|
11 |
-
const [subTab, setSubTab] = useState(0)
|
12 |
-
|
13 |
-
return (<div>
|
14 |
-
<Modal
|
15 |
-
basic
|
16 |
-
className=''
|
17 |
-
open={props.open}
|
18 |
-
size='fullscreen'
|
19 |
-
>
|
20 |
-
<div className='w-full shadow-lg rounded-lg'>
|
21 |
-
<ul className="flex flex-wrap text-sm font-medium text-center text-gray-500 bg-gray-100 rounded-t-lg border-gray-200 dark:border-gray-700 dark:text-gray-400 dark:bg-gray-800" id="defaultTab" data-tabs-toggle="#defaultTabContent" role="tablist">
|
22 |
-
<li className="" onClick={()=>{
|
23 |
-
setTab("gradio")
|
24 |
-
props.catch ? props.handelError(false) : props.handelError(props.catch) }}>
|
25 |
-
<button id="gradio-tab" data-tabs-target="#Gradio" type="button" role="tab" aria-controls="gradio" aria-selected={tab === "gradio" ? "true" : "false"} className={`inline-block p-4 rounded-tl-lg ${ tab === "gradio" ? 'bg-gray-200' : 'hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-700 focus:bg-gray-700'}`}><Gradio className=" w-20 h-10"/></button>
|
26 |
-
</li>
|
27 |
-
<li className="" onClick={()=>{
|
28 |
-
setTab("streamlit")
|
29 |
-
props.catch ? props.handelError(false) : props.handelError(props.catch) }}>
|
30 |
-
<button id="services-tab" data-tabs-target="#Streamlit" type="button" role="tab" aria-controls="services" aria-selected="false" className={`inline-block p-4 rounded-tl-lg ${ tab === "streamlit" ? 'bg-gray-200' : 'hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-700 focus:bg-gray-700'}`}><Streamlit className=" w-20 h-10"/></button>
|
31 |
-
</li>
|
32 |
-
</ul>
|
33 |
-
<div className='absolute right-5 top-5 z-20 mr-5'
|
34 |
-
onClick={()=>{
|
35 |
-
props.quitHandeler(false)
|
36 |
-
props.catch ? props.handelError(false) : props.handelError(props.catch) }}>
|
37 |
-
<button type="button"
|
38 |
-
className=" bg-neutral-300 rounded-2xl p-2 inline-flex items-center justify-center dark:bg-neutral-700 hover:opacity-70 focus:outline-none">
|
39 |
-
<Exit className=" w-[20px] h-[20px] text-gray-400 dark:text-white"/>
|
40 |
-
</button>
|
41 |
-
</div>
|
42 |
-
</div>
|
43 |
-
{ tab === "gradio" &&
|
44 |
-
<div className='w-full bg-white'>
|
45 |
-
<ul className="flex flex-wrap text-sm font-medium text-center text-gray-500 bg-gray-200 border-gray-200 dark:border-gray-700 dark:text-gray-400 dark:bg-gray-800" id="defaultTab" data-tabs-toggle="#defaultTabContent" role="tablist">
|
46 |
-
<li className="" onClick={()=>{
|
47 |
-
setSubTab(0)
|
48 |
-
props.catch ? props.handelError(false) : props.handelError(props.catch) }}>
|
49 |
-
<button id="local-sub-tab" data-tabs-target="#local" type="button" role="tab" aria-controls="local-gradio" aria-selected={tab === "gradio" ? "true" : "false"} className={`inline-block p-4 px-6 text-base font-sans font-bold ${subTab === 0 ? 'bg-gray-300' : '' } hover:bg-gray-300 `}>Local</button>
|
50 |
-
</li>
|
51 |
-
<li className="" onClick={()=>{
|
52 |
-
setSubTab(1)
|
53 |
-
props.catch ? props.handelError(false) : props.handelError(props.catch) }}>
|
54 |
-
<button id="shared-sub-tab" data-tabs-target="#Gradio" type="button" role="tab" aria-controls="shared-gradio" aria-selected={tab === "gradio" ? "true" : "false"} className={`inline-block p-4 px-6 text-base font-sans font-bold ${subTab === 1 ? 'bg-gray-300' : '' } hover:bg-gray-300 `}>Shared</button>
|
55 |
-
</li>
|
56 |
-
</ul>
|
57 |
-
{subTab === 0 && <Local/>}
|
58 |
-
{subTab === 1 && <Shared type="gradio" textHandler={props.textHandler} appendHandler={props.appendHandler} handelError={props.handelError} catch={props.catch}/>}
|
59 |
-
|
60 |
-
{props.catch && <div className='p-5'>
|
61 |
-
<Message floating negative>
|
62 |
-
<Message.Header className=" text-lg text-center">🚫 Something went wrong...</Message.Header>
|
63 |
-
<br/>
|
64 |
-
<h1 className=" underline pb-3 font-bold text-lg">🤔 Possible Things That could of happen <br/></h1>
|
65 |
-
<ul className="font-bold">
|
66 |
-
<li key={"error_1"}>- The input was empty</li>
|
67 |
-
<li key={"error_2"}>- The connection was forbidden</li>
|
68 |
-
<li key={"error_3"}>- The name was already taken</li>
|
69 |
-
<li key={"error_4"}>- The link you gave did not pass the regex</li>
|
70 |
-
<ul className="px-6">
|
71 |
-
<li key={"error_5"}>- http://localhost:xxxx</li>
|
72 |
-
<li key={"error_6"}>- http://xxxxx.gradio.app</li>
|
73 |
-
<li key={"error_7"}>- https://hf.space/embed/$user/$space_name/+</li>
|
74 |
-
</ul>
|
75 |
-
<li>- link already exist within the menu</li>
|
76 |
-
</ul>
|
77 |
-
|
78 |
-
</Message>
|
79 |
-
</div>}
|
80 |
-
</div>
|
81 |
-
}
|
82 |
-
{ tab === "streamlit" &&
|
83 |
-
<div className='w-full bg-white'>
|
84 |
-
<Shared type="streamlit" textHandler={props.textHandler} appendHandler={props.appendHandler} handelError={props.handelError} catch={props.catch}/>
|
85 |
-
</div>
|
86 |
-
}
|
87 |
-
|
88 |
-
</Modal>
|
89 |
-
</div>)
|
90 |
-
}
|
91 |
-
|
92 |
-
function Local(props){
|
93 |
-
return (
|
94 |
-
<div className='p-5'>
|
95 |
-
<Message floating>
|
96 |
-
|
97 |
-
<Message.Header>🏗️ Comming soon...</Message.Header>
|
98 |
-
<Message.Content className='p-5'>
|
99 |
-
This tab will allow you grab your function from a given directory and build
|
100 |
-
your own tabular module gradio functions
|
101 |
-
</Message.Content>
|
102 |
-
|
103 |
-
</Message>
|
104 |
-
</div>
|
105 |
-
)
|
106 |
-
}
|
107 |
-
|
108 |
-
function Shared(props){
|
109 |
-
const [preview, setPreview] = useState("")
|
110 |
-
const [fetchable, setFetch] = useState(false)
|
111 |
-
|
112 |
-
const isFetchable = async (url) => {
|
113 |
-
const pattern = {
|
114 |
-
share : /^https?:\/\/*([0-9]{5})*(-gradio)*(.app)?(\/)?$/,
|
115 |
-
hugginFace : /^https?:\/\/*(hf.space)\/*(embed)\/*([a-zA-Z0-9+_-]+)\/*([a-zA-Z0-9+_-]+)\/*([+])?(\/)?$/
|
116 |
-
}
|
117 |
-
|
118 |
-
if (!pattern.share.test(url) &&
|
119 |
-
!pattern.hugginFace.test(url)){
|
120 |
-
setFetch(false)
|
121 |
-
return
|
122 |
-
}
|
123 |
-
|
124 |
-
|
125 |
-
fetch(url, {mode : "no-cors"}).then((re) => {
|
126 |
-
console.log(re)
|
127 |
-
if(re.url.includes("http://localhost:3000")){
|
128 |
-
setFetch(false)
|
129 |
-
} else {
|
130 |
-
setFetch(true)
|
131 |
-
props.catch ? props.handelError(false) : props.handelError(props.catch)
|
132 |
-
}
|
133 |
-
|
134 |
-
}).catch((err)=>{
|
135 |
-
setFetch(false)
|
136 |
-
})
|
137 |
-
setFetch(false)
|
138 |
-
}
|
139 |
-
|
140 |
-
return (
|
141 |
-
<div className='w-full shadow-lg' onKeyPress={(e)=>{
|
142 |
-
if (e.key.includes("Enter")) props.appendHandler(props.type)
|
143 |
-
}}>
|
144 |
-
<div className='p-5'>
|
145 |
-
<Message floating>
|
146 |
-
<div className={`flex items-center rounded-md bg-light-white mt-6 border-dashed`}>
|
147 |
-
<label className="relative block w-full p-5 focus:shadow-xl">
|
148 |
-
<span className={`absolute inset-y-0 left-0 flex items-center pl-8`}>
|
149 |
-
<BsSearch className="block float-left cursor-pointer text-gray-500"/>
|
150 |
-
</span>
|
151 |
-
<input className={`placeholder:italic placeholder:text-slate-400 text-black dark:text-white block w-full border border-slate-300 border-dashed rounded-md py-2 pl-9 pr-3 focus:shadow-xl focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-sm bg-transparent`}
|
152 |
-
placeholder={`URL`}
|
153 |
-
type="text" name="search"
|
154 |
-
onChange={(e) => {
|
155 |
-
props.textHandler(e, "text")
|
156 |
-
setPreview(e.target.value)
|
157 |
-
setFetch(isFetchable(e.target.value))
|
158 |
-
}}
|
159 |
-
/>
|
160 |
-
</label>
|
161 |
-
</div>
|
162 |
-
{ fetchable === true && <div className=' w-full'>
|
163 |
-
<h1 className=' text-xl font-sans font-bold text-center text-black mb-2'> Preview </h1>
|
164 |
-
<div className='p-3 px-1 w-3/4 h-80 bg-gray-200 mr-auto ml-auto rounded-xl'>
|
165 |
-
<div className='w-full h-full overflow-hidden relative -ml-[5px]'>
|
166 |
-
<iframe title='Preview' src={preview} className=' absolute top-0 bottom-0 left-0 -right-[25px] overflow-y-scroll w-full h-full mr-auto ml-auto'/>
|
167 |
-
</div>
|
168 |
-
</div>
|
169 |
-
</div>}
|
170 |
-
<div className={`flex items-center rounded-md bg-light-white dark:bg-[#1b1c1d] mt-6 border-dashed`}>
|
171 |
-
<label className="relative block p-5 w-full focus:shadow-xl">
|
172 |
-
<span className={`absolute inset-y-0 left-0 flex items-center pl-7`}>
|
173 |
-
<Icon className=" text-gray-500 block float-left cursor-pointer mr-2" name="address card"/>
|
174 |
-
</span>
|
175 |
-
<input className={`placeholder:italic placeholder:text-slate-400 text-black dark:text-white block bg-transparent w-full border border-slate-300 border-dashed rounded-md py-2 pl-9 pr-3 focus:shadow-xl focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-sm`}
|
176 |
-
placeholder={`Name ( > 20 Characters)` }
|
177 |
-
type="text" name="search"
|
178 |
-
autoComplete='off'
|
179 |
-
onChange={(e) => {
|
180 |
-
props.textHandler(e, "name")
|
181 |
-
}}
|
182 |
-
/>
|
183 |
-
</label>
|
184 |
-
</div>
|
185 |
-
<div className=' right-0 ml-5'>
|
186 |
-
<button className="relative inline-flex justify-center p-0.5 mb-2 mr-2 overflow-hidden text-sm font-sans font-bold text-gray-900 rounded-lg group bg-gradient-to-br from-purple-600 to-blue-500 group-hover:from-purple-600 group-hover:to-blue-500 hover:text-white dark:text-white focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800"
|
187 |
-
onClick={()=>{props.appendHandler(props.type)}}>
|
188 |
-
<span className="relative px-5 py-2.5 transition-all ease-in duration-75 bg-white dark:bg-[#1b1c1d] rounded-md group-hover:bg-opacity-0">
|
189 |
-
Enter
|
190 |
-
</span>
|
191 |
-
</button>
|
192 |
-
</div>
|
193 |
-
</Message>
|
194 |
-
</div>
|
195 |
-
</div>
|
196 |
-
|
197 |
-
)
|
198 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|