Spaces:
Sleeping
Sleeping
acecalisto3
commited on
Delete types.py
Browse files
types.py
DELETED
@@ -1,150 +0,0 @@
|
|
1 |
-
from enum import Enum
|
2 |
-
from typing import List, Dict, Optional
|
3 |
-
from types import Code, Prompt, AppType, File, Space, Tutorial, App, WebApp, Gradio, StreamlitApp, ReactApp
|
4 |
-
|
5 |
-
class AppType(Enum):
|
6 |
-
WEB_APP = "web_app"
|
7 |
-
GRADIO_APP = "gradio_app"
|
8 |
-
STREAMLIT_APP = "streamlit_app"
|
9 |
-
REACT_APP = "react_app"
|
10 |
-
|
11 |
-
import hashlib
|
12 |
-
import os
|
13 |
-
import time
|
14 |
-
from typing import Optional
|
15 |
-
|
16 |
-
|
17 |
-
class Code:import hashlib
|
18 |
-
import os
|
19 |
-
import time
|
20 |
-
from typing import Optional
|
21 |
-
|
22 |
-
class Code:
|
23 |
-
def __init__(self, code: str, language: str):
|
24 |
-
self.code = code
|
25 |
-
self.language = language
|
26 |
-
|
27 |
-
def get_code_length(self) -> int:
|
28 |
-
return len(self.code)
|
29 |
-
|
30 |
-
def get_language(self) -> str:
|
31 |
-
return self.language
|
32 |
-
|
33 |
-
def hash_code(self) -> str:
|
34 |
-
return hashlib.sha256(self.code.encode()).hexdigest()
|
35 |
-
|
36 |
-
class Prompt:
|
37 |
-
def __init__(self, prompt: str):
|
38 |
-
self.prompt = prompt
|
39 |
-
|
40 |
-
def get_prompt_length(self) -> int:
|
41 |
-
return len(self.prompt)
|
42 |
-
|
43 |
-
def preview_prompt(self, length: int = 50) -> str:
|
44 |
-
return self.prompt[:length] + ('...' if len(self.prompt) > length else '')
|
45 |
-
|
46 |
-
class AppType:
|
47 |
-
def __init__(self, app_type: str):
|
48 |
-
self.app_type = app_type
|
49 |
-
|
50 |
-
def is_web_app(self) -> bool:
|
51 |
-
return self.app_type.lower() == 'web'
|
52 |
-
|
53 |
-
def is_gradio_app(self) -> bool:
|
54 |
-
return self.app_type.lower() == 'gradio'
|
55 |
-
|
56 |
-
def is_streamlit_app(self) -> bool:
|
57 |
-
return self.app_type.lower() == 'streamlit'
|
58 |
-
|
59 |
-
def is_react_app(self) -> bool:
|
60 |
-
return self.app_type.lower() == 'react'
|
61 |
-
|
62 |
-
class File:
|
63 |
-
def __init__(self, path: str, content: str):
|
64 |
-
self.path = path
|
65 |
-
self.content = content
|
66 |
-
|
67 |
-
def save(self) -> None:
|
68 |
-
with open(self.path, 'w') as file:
|
69 |
-
file.write(self.content)
|
70 |
-
|
71 |
-
def load(self) -> None:
|
72 |
-
if os.path.exists(self.path):
|
73 |
-
with open(self.path, 'r') as file:
|
74 |
-
self.content = file.read()
|
75 |
-
|
76 |
-
def get_file_size(self) -> int:
|
77 |
-
return len(self.content)
|
78 |
-
|
79 |
-
class Space:
|
80 |
-
def __init__(self, space: str):
|
81 |
-
self.space = space
|
82 |
-
|
83 |
-
def get_space_name(self) -> str:
|
84 |
-
return self.space
|
85 |
-
|
86 |
-
class Tutorial:
|
87 |
-
def __init__(self, tutorial: str):
|
88 |
-
self.tutorial = tutorial
|
89 |
-
|
90 |
-
def get_tutorial_length(self) -> int:
|
91 |
-
return len(self.tutorial)
|
92 |
-
|
93 |
-
def preview_tutorial(self, length: int = 100) -> str:
|
94 |
-
return self.tutorial[:length] + ('...' if len(self.tutorial) > length else '')
|
95 |
-
|
96 |
-
class App:
|
97 |
-
def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
|
98 |
-
self.code = code
|
99 |
-
self.app_type = app_type
|
100 |
-
self.space = space
|
101 |
-
self.tutorial = tutorial
|
102 |
-
self._id = self.generate_id()
|
103 |
-
|
104 |
-
def generate_id(self) -> str:
|
105 |
-
return f"app-{hashlib.md5(str(time.time()).encode()).hexdigest()}"
|
106 |
-
|
107 |
-
def launch(self) -> None:
|
108 |
-
print(f"Launching app {self._id}...")
|
109 |
-
|
110 |
-
class WebApp(App):
|
111 |
-
def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
|
112 |
-
super().__init__(code, app_type, space, tutorial)
|
113 |
-
|
114 |
-
def launch(self) -> None:
|
115 |
-
super().launch()
|
116 |
-
print("WebApp specific launch sequence...")
|
117 |
-
|
118 |
-
class GradioApp(App):
|
119 |
-
def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
|
120 |
-
super().__init__(code, app_type, space, tutorial)
|
121 |
-
|
122 |
-
def launch(self) -> None:
|
123 |
-
super().launch()
|
124 |
-
print("GradioApp specific launch sequence...")
|
125 |
-
|
126 |
-
class StreamlitApp(App):
|
127 |
-
def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
|
128 |
-
super().__init__(code, app_type, space, tutorial)
|
129 |
-
|
130 |
-
def launch(self) -> None:
|
131 |
-
super().launch()
|
132 |
-
print("StreamlitApp specific launch sequence...")
|
133 |
-
|
134 |
-
class ReactApp(App):
|
135 |
-
def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
|
136 |
-
super().__init__(code, app_type, space, tutorial)
|
137 |
-
|
138 |
-
def launch(self) -> None:
|
139 |
-
super().launch()
|
140 |
-
print("ReactApp specific launch sequence...")
|
141 |
-
|
142 |
-
# Example usage
|
143 |
-
if __name__ == "__main__":
|
144 |
-
code = Code("example code", "python")
|
145 |
-
app_type = AppType("web")
|
146 |
-
space = Space("example space")
|
147 |
-
tutorial = Tutorial("example tutorial")
|
148 |
-
|
149 |
-
app = WebApp(code, app_type, space, tutorial)
|
150 |
-
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|