acecalisto3 commited on
Commit
4c13fae
·
verified ·
1 Parent(s): 67594d5

Update cust_types.py

Browse files
Files changed (1) hide show
  1. cust_types.py +111 -28
cust_types.py CHANGED
@@ -8,54 +8,137 @@ class AppType(Enum):
8
  STREAMLIT_APP = "streamlit_app"
9
  REACT_APP = "react_app"
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  class Prompt:
12
  def __init__(self, prompt: str):
13
  self.prompt = prompt
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  class Space:
16
  def __init__(self, space: str):
17
  self.space = space
18
 
 
 
 
19
  class Tutorial:
20
  def __init__(self, tutorial: str):
21
  self.tutorial = tutorial
22
 
23
- class File:
24
- def __init__(self, name: str, content: str, language: str):
25
- self.name = name
26
- self.content = content
27
- self.language = language
28
 
29
  class App:
30
- def __init__(self, app_type: AppType, app_name: str, app_description: str, app_features: List[str], app_dependencies: List[str], app_space: Optional[Space] = None, app_tutorial: Optional[Tutorial] = None):
 
31
  self.app_type = app_type
32
- self.app_name = app_name
33
- self.app_description = app_description
34
- self.app_features = app_features
35
- self.app_dependencies = app_dependencies
36
- self.app_space = app_space
37
- self.app_tutorial = app_tutorial
 
 
 
38
 
39
  class WebApp(App):
40
- def __init__(self, code: str, language: str, app_type: AppType = AppType.WEB_APP, app_name: str = "WebApp", app_description: str = "A simple web application", app_features: List[str] = ["Basic HTML structure", "Title and description", "Simple styling"], app_dependencies: List[str] = ["HTML", "CSS"], app_space: Optional[Space] = None, app_tutorial: Optional[Tutorial] = None):
41
- super().__init__(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial)
42
- self.code = code
43
- self.language = language
 
 
44
 
45
  class GradioApp(App):
46
- def __init__(self, code: str, language: str, app_type: AppType = AppType.GRADIO_APP, app_name: str = "GradioApp", app_description: str = "A simple Gradio application", app_features: List[str] = ["Basic Gradio interface", "Input and output components", "Simple function"], app_dependencies: List[str] = ["Gradio", "Python"], app_space: Optional[Space] = None, app_tutorial: Optional[Tutorial] = None):
47
- super().__init__(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial)
48
- self.code = code
49
- self.language = language
 
 
50
 
51
  class StreamlitApp(App):
52
- def __init__(self, code: str, language: str, app_type: AppType = AppType.STREAMLIT_APP, app_name: str = "StreamlitApp", app_description: str = "A simple Streamlit application", app_features: List[str] = ["Basic Streamlit interface", "Title and description", "Simple layout"], app_dependencies: List[str] = ["Streamlit", "Python"], app_space: Optional[Space] = None, app_tutorial: Optional[Tutorial] = None):
53
- super().__init__(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial)
54
- self.code = code
55
- self.language = language
 
 
56
 
57
  class ReactApp(App):
58
- def __init__(self, code: str, language: str, app_type: AppType = AppType.REACT_APP, app_name: str = "ReactApp", app_description: str = "A simple React application", app_features: List[str] = ["Basic React component", "JSX syntax", "State management"], app_dependencies: List[str] = ["React", "JavaScript"], app_space: Optional[Space] = None, app_tutorial: Optional[Tutorial] = None):
59
- super().__init__(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial)
60
- self.code = code
61
- self.language = language
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ class Code:
17
+ def __init__(self, code: str, language: str):
18
+ self.code = code
19
+ self.language = language
20
+
21
+ def get_code_length(self) -> int:
22
+ return len(self.code)
23
+
24
+ def get_language(self) -> str:
25
+ return self.language
26
+
27
+ def hash_code(self) -> str:
28
+ return hashlib.sha256(self.code.encode()).hexdigest()
29
+
30
  class Prompt:
31
  def __init__(self, prompt: str):
32
  self.prompt = prompt
33
 
34
+ def get_prompt_length(self) -> int:
35
+ return len(self.prompt)
36
+
37
+ def preview_prompt(self, length: int = 50) -> str:
38
+ return self.prompt[:length] + ('...' if len(self.prompt) > length else '')
39
+
40
+ class AppType:
41
+ def __init__(self, app_type: str):
42
+ self.app_type = app_type
43
+
44
+ def is_web_app(self) -> bool:
45
+ return self.app_type.lower() == 'web'
46
+
47
+ def is_gradio_app(self) -> bool:
48
+ return self.app_type.lower() == 'gradio'
49
+
50
+ def is_streamlit_app(self) -> bool:
51
+ return self.app_type.lower() == 'streamlit'
52
+
53
+ def is_react_app(self) -> bool:
54
+ return self.app_type.lower() == 'react'
55
+
56
+ class File:
57
+ def __init__(self, path: str, content: str):
58
+ self.path = path
59
+ self.content = content
60
+
61
+ def save(self) -> None:
62
+ with open(self.path, 'w') as file:
63
+ file.write(self.content)
64
+
65
+ def load(self) -> None:
66
+ if os.path.exists(self.path):
67
+ with open(self.path, 'r') as file:
68
+ self.content = file.read()
69
+
70
+ def get_file_size(self) -> int:
71
+ return len(self.content)
72
+
73
  class Space:
74
  def __init__(self, space: str):
75
  self.space = space
76
 
77
+ def get_space_name(self) -> str:
78
+ return self.space
79
+
80
  class Tutorial:
81
  def __init__(self, tutorial: str):
82
  self.tutorial = tutorial
83
 
84
+ def get_tutorial_length(self) -> int:
85
+ return len(self.tutorial)
86
+
87
+ def preview_tutorial(self, length: int = 100) -> str:
88
+ return self.tutorial[:length] + ('...' if len(self.tutorial) > length else '')
89
 
90
  class App:
91
+ def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
92
+ self.code = code
93
  self.app_type = app_type
94
+ self.space = space
95
+ self.tutorial = tutorial
96
+ self._id = self.generate_id()
97
+
98
+ def generate_id(self) -> str:
99
+ return f"app-{hashlib.md5(str(time.time()).encode()).hexdigest()}"
100
+
101
+ def launch(self) -> None:
102
+ print(f"Launching app {self._id}...")
103
 
104
  class WebApp(App):
105
+ def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
106
+ super().__init__(code, app_type, space, tutorial)
107
+
108
+ def launch(self) -> None:
109
+ super().launch()
110
+ print("WebApp specific launch sequence...")
111
 
112
  class GradioApp(App):
113
+ def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
114
+ super().__init__(code, app_type, space, tutorial)
115
+
116
+ def launch(self) -> None:
117
+ super().launch()
118
+ print("GradioApp specific launch sequence...")
119
 
120
  class StreamlitApp(App):
121
+ def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
122
+ super().__init__(code, app_type, space, tutorial)
123
+
124
+ def launch(self) -> None:
125
+ super().launch()
126
+ print("StreamlitApp specific launch sequence...")
127
 
128
  class ReactApp(App):
129
+ def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
130
+ super().__init__(code, app_type, space, tutorial)
131
+
132
+ def launch(self) -> None:
133
+ super().launch()
134
+ print("ReactApp specific launch sequence...")
135
+
136
+ # Example usage
137
+ if __name__ == "__main__":
138
+ code = Code("example code", "python")
139
+ app_type = AppType("web")
140
+ space = Space("example space")
141
+ tutorial = Tutorial("example tutorial")
142
+
143
+ app = WebApp(code, app_type, space, tutorial)
144
+ app.launch()