acecalisto3 commited on
Commit
67594d5
·
verified ·
1 Parent(s): 3186e54

Update custom_types.py

Browse files
Files changed (1) hide show
  1. custom_types.py +79 -17
custom_types.py CHANGED
@@ -1,72 +1,134 @@
1
- from custom_types import SomeClass # Updated import
 
 
 
2
 
3
  class Code:
4
  def __init__(self, code: str, language: str):
5
  self.code = code
6
  self.language = language
7
 
 
 
 
 
 
 
 
 
 
8
  class Prompt:
9
  def __init__(self, prompt: str):
10
  self.prompt = prompt
11
 
 
 
 
 
 
 
12
  class AppType:
13
  def __init__(self, app_type: str):
14
  self.app_type = app_type
15
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  class File:
17
  def __init__(self, path: str, content: str):
18
  self.path = path
19
  self.content = content
20
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  class Space:
22
  def __init__(self, space: str):
23
  self.space = space
24
 
 
 
 
25
  class Tutorial:
26
  def __init__(self, tutorial: str):
27
  self.tutorial = tutorial
28
 
 
 
 
 
 
 
29
  class App:
30
  def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
31
  self.code = code
32
  self.app_type = app_type
33
  self.space = space
34
  self.tutorial = tutorial
35
- self._id = None
36
 
37
- def generate_id(self):
38
- # Simple id generation for demonstration purposes
39
- return f"app-{id(self)}"
40
 
41
- def launch(self):
42
- # Simulate launching the app
43
  print(f"Launching app {self._id}...")
44
 
45
  class WebApp(App):
46
  def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
47
  super().__init__(code, app_type, space, tutorial)
48
- self._id = self.generate_id()
 
 
 
49
 
50
  class GradioApp(App):
51
  def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
52
  super().__init__(code, app_type, space, tutorial)
53
- self._id = self.generate_id()
 
 
 
54
 
55
  class StreamlitApp(App):
56
  def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
57
  super().__init__(code, app_type, space, tutorial)
58
- self._id = self.generate_id()
 
 
 
59
 
60
  class ReactApp(App):
61
  def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
62
  super().__init__(code, app_type, space, tutorial)
63
- self._id = self.generate_id()
 
 
 
64
 
65
  # Example usage
66
- code = Code("example code", "python")
67
- app_type = AppType("web")
68
- space = Space("example space")
69
- tutorial = Tutorial("example tutorial")
 
70
 
71
- app = WebApp(code, app_type, space, tutorial)
72
- app.launch()
 
1
+ import hashlib
2
+ import os
3
+ import time
4
+ from typing import Optional
5
 
6
  class Code:
7
  def __init__(self, code: str, language: str):
8
  self.code = code
9
  self.language = language
10
 
11
+ def get_code_length(self) -> int:
12
+ return len(self.code)
13
+
14
+ def get_language(self) -> str:
15
+ return self.language
16
+
17
+ def hash_code(self) -> str:
18
+ return hashlib.sha256(self.code.encode()).hexdigest()
19
+
20
  class Prompt:
21
  def __init__(self, prompt: str):
22
  self.prompt = prompt
23
 
24
+ def get_prompt_length(self) -> int:
25
+ return len(self.prompt)
26
+
27
+ def preview_prompt(self, length: int = 50) -> str:
28
+ return self.prompt[:length] + ('...' if len(self.prompt) > length else '')
29
+
30
  class AppType:
31
  def __init__(self, app_type: str):
32
  self.app_type = app_type
33
 
34
+ def is_web_app(self) -> bool:
35
+ return self.app_type.lower() == 'web'
36
+
37
+ def is_gradio_app(self) -> bool:
38
+ return self.app_type.lower() == 'gradio'
39
+
40
+ def is_streamlit_app(self) -> bool:
41
+ return self.app_type.lower() == 'streamlit'
42
+
43
+ def is_react_app(self) -> bool:
44
+ return self.app_type.lower() == 'react'
45
+
46
  class File:
47
  def __init__(self, path: str, content: str):
48
  self.path = path
49
  self.content = content
50
 
51
+ def save(self) -> None:
52
+ with open(self.path, 'w') as file:
53
+ file.write(self.content)
54
+
55
+ def load(self) -> None:
56
+ if os.path.exists(self.path):
57
+ with open(self.path, 'r') as file:
58
+ self.content = file.read()
59
+
60
+ def get_file_size(self) -> int:
61
+ return len(self.content)
62
+
63
  class Space:
64
  def __init__(self, space: str):
65
  self.space = space
66
 
67
+ def get_space_name(self) -> str:
68
+ return self.space
69
+
70
  class Tutorial:
71
  def __init__(self, tutorial: str):
72
  self.tutorial = tutorial
73
 
74
+ def get_tutorial_length(self) -> int:
75
+ return len(self.tutorial)
76
+
77
+ def preview_tutorial(self, length: int = 100) -> str:
78
+ return self.tutorial[:length] + ('...' if len(self.tutorial) > length else '')
79
+
80
  class App:
81
  def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
82
  self.code = code
83
  self.app_type = app_type
84
  self.space = space
85
  self.tutorial = tutorial
86
+ self._id = self.generate_id()
87
 
88
+ def generate_id(self) -> str:
89
+ return f"app-{hashlib.md5(str(time.time()).encode()).hexdigest()}"
 
90
 
91
+ def launch(self) -> None:
 
92
  print(f"Launching app {self._id}...")
93
 
94
  class WebApp(App):
95
  def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
96
  super().__init__(code, app_type, space, tutorial)
97
+
98
+ def launch(self) -> None:
99
+ super().launch()
100
+ print("WebApp specific launch sequence...")
101
 
102
  class GradioApp(App):
103
  def __init__(self, code: Code, app_type: AppType, space: Space, tutorial: Tutorial):
104
  super().__init__(code, app_type, space, tutorial)
105
+
106
+ def launch(self) -> None:
107
+ super().launch()
108
+ print("GradioApp specific launch sequence...")
109
 
110
  class StreamlitApp(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("StreamlitApp specific launch sequence...")
117
 
118
  class ReactApp(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("ReactApp specific launch sequence...")
125
 
126
  # Example usage
127
+ if __name__ == "__main__":
128
+ code = Code("example code", "python")
129
+ app_type = AppType("web")
130
+ space = Space("example space")
131
+ tutorial = Tutorial("example tutorial")
132
 
133
+ app = WebApp(code, app_type, space, tutorial)
134
+ app.launch()