acecalisto3 commited on
Commit
d7dff8e
1 Parent(s): c662af4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -222
app.py CHANGED
@@ -1,5 +1,4 @@
1
  from typing import List, Dict, Optional
2
-
3
  from cust_types import (
4
  Code,
5
  Prompt,
@@ -14,7 +13,6 @@ from cust_types import (
14
  ReactApp,
15
  Code,
16
  )
17
-
18
  from agent import Agent
19
 
20
  # Import the translated functions from the .py files
@@ -36,229 +34,10 @@ from isStreamlitAppPrompt import isStreamlitAppPrompt
36
  from main import main
37
  from parseTutorial import parseTutorial
38
  from streamlitDoc import streamlitDoc
39
- from types import AppType
40
  from typescript import typescript
41
 
42
- class Agent:
43
- def __init__(self, prompts: Dict[str, any]):
44
- self.prompts = prompts
45
- self.client = InferenceClient(
46
- "mistralai/Mixtral-8x7B-Instruct-v0.1"
47
- )
48
-
49
- def process(self, user_input: str) -> str:
50
- """
51
- Processes the user's input and generates code.
52
- """
53
-
54
- # Parse the user's input
55
- app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial = self.parse_input(user_input)
56
-
57
- # Generate a prompt for the Llama model
58
- prompt = self.prompts["createLlamaPrompt"](
59
- app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial
60
- )
61
-
62
- # Generate code using the Llama model
63
- code = self.generate_code(prompt)
64
-
65
- # Generate files for the application
66
- files = self.prompts["generateFiles"](
67
- app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial
68
- )
69
-
70
- # Return the generated code and files
71
- return f"Code: {code}\nFiles: {files}"
72
-
73
- def parse_input(self, user_input: str) -> tuple:
74
- """
75
- Parses the user's input and extracts the relevant information.
76
- """
77
-
78
- # Extract the app type
79
- app_type = self.extract_app_type(user_input)
80
-
81
- # Extract the app name
82
- app_name = self.extract_app_name(user_input)
83
-
84
- # Extract the app description
85
- app_description = self.extract_app_description(user_input)
86
-
87
- # Extract the app features
88
- app_features = self.extract_app_features(user_input)
89
-
90
- # Extract the app dependencies
91
- app_dependencies = self.extract_app_dependencies(user_input)
92
-
93
- # Extract the app space
94
- app_space = self.extract_app_space(user_input)
95
-
96
- # Extract the app tutorial
97
- app_tutorial = self.extract_app_tutorial(user_input)
98
-
99
- return app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial
100
-
101
- def extract_app_type(self, user_input: str) -> AppType:
102
- """
103
- Extracts the app type from the user's input.
104
- """
105
-
106
- # Check if the user specified a specific app type
107
- if "web app" in user_input:
108
- return AppType.WEB_APP
109
- elif "gradio app" in user_input:
110
- return AppType.GRADIO_APP
111
- elif "streamlit app" in user_input:
112
- return AppType.STREAMLIT_APP
113
- elif "react app" in user_input:
114
- return AppType.REACT_APP
115
-
116
- # Otherwise, assume the user wants a web app
117
- return AppType.WEB_APP
118
-
119
- def extract_app_name(self, user_input: str) -> str:
120
- """
121
- Extracts the app name from the user's input.
122
- """
123
-
124
- # Find the substring "app name is:"
125
- start_index = user_input.find("app name is:") + len("app name is:")
126
-
127
- # Find the end of the app name
128
- end_index = user_input.find(".", start_index)
129
-
130
- # Extract the app name
131
- app_name = user_input[start_index:end_index].strip()
132
-
133
- return app_name
134
-
135
- def extract_app_description(self, user_input: str) -> str:
136
- """
137
- Extracts the app description from the user's input.
138
- """
139
-
140
- # Find the substring "app description is:"
141
- start_index = user_input.find("app description is:") + len("app description is:")
142
-
143
- # Find the end of the app description
144
- end_index = user_input.find(".", start_index)
145
-
146
- # Extract the app description
147
- app_description = user_input[start_index:end_index].strip()
148
-
149
- return app_description
150
-
151
- def extract_app_features(self, user_input: str) -> List[str]:
152
- """
153
- Extracts the app features from the user's input.
154
- """
155
-
156
- # Find the substring "app features are:"
157
- start_index = user_input.find("app features are:") + len("app features are:")
158
-
159
- # Find the end of the app features
160
- end_index = user_input.find(".", start_index)
161
-
162
- # Extract the app features
163
- app_features_str = user_input[start_index:end_index].strip()
164
-
165
- # Split the app features string into a list
166
- app_features = app_features_str.split(", ")
167
-
168
- return app_features
169
-
170
- def extract_app_dependencies(self, user_input: str) -> List[str]:
171
- """
172
- Extracts the app dependencies from the user's input.
173
- """
174
-
175
- # Find the substring "app dependencies are:"
176
- start_index = user_input.find("app dependencies are:") + len("app dependencies are:")
177
-
178
- # Find the end of the app dependencies
179
- end_index = user_input.find(".", start_index)
180
-
181
- # Extract the app dependencies
182
- app_dependencies_str = user_input[start_index:end_index].strip()
183
-
184
- # Split the app dependencies string into a list
185
- app_dependencies = app_dependencies_str.split(", ")
186
-
187
- return app_dependencies
188
-
189
- def extract_app_space(self, user_input: str) -> Optional[Space]:
190
- """
191
- Extracts the app space from the user's input.
192
- """
193
-
194
- # Find the substring "app space is:"
195
- start_index = user_input.find("app space is:") + len("app space is:")
196
-
197
- # Find the end of the app space
198
- end_index = user_input.find(".", start_index)
199
-
200
- # Extract the app space
201
- app_space_str = user_input[start_index:end_index].strip()
202
-
203
- # Create a Space object
204
- app_space = Space(space=app_space_str)
205
-
206
- return app_space
207
-
208
- def extract_app_tutorial(self, user_input: str) -> Optional[Tutorial]:
209
- """
210
- Extracts the app tutorial from the user's input.
211
- """
212
-
213
- # Find the substring "app tutorial is:"
214
- start_index = user_input.find("app tutorial is:") + len("app tutorial is:")
215
-
216
- # Find the end of the app tutorial
217
- end_index = user_input.find(".", start_index)
218
-
219
- # Extract the app tutorial
220
- app_tutorial_str = user_input[start_index:end_index].strip()
221
-
222
- # Create a Tutorial object
223
- app_tutorial = Tutorial(tutorial=app_tutorial_str)
224
-
225
- return app_tutorial
226
-
227
- def generate_code(self, prompt: Prompt) -> Code:
228
- """
229
- Generates code using the Llama model.
230
- """
231
-
232
- # Send the prompt to the Llama model
233
- response = self.client(prompt.prompt)
234
-
235
- # Extract the generated code
236
- code = response["generated_text"]
237
- code = code.replace("```", "")
238
- code = code.replace("```", "")
239
-
240
- # Create a Code object
241
- code = Code(code=code, language="python")
242
-
243
- return code
244
-
245
- def generate_files(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) -> List[File]:
246
- """
247
- Generates files for the application.
248
- """
249
-
250
- # Generate files based on the app type
251
- files = self.prompts["generateFiles"](
252
- app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial
253
- )
254
-
255
- return files
256
-
257
  def main():
258
- """
259
- Main function for the application.
260
- """
261
-
262
  # Create an agent
263
  agent = Agent(
264
  prompts={
 
1
  from typing import List, Dict, Optional
 
2
  from cust_types import (
3
  Code,
4
  Prompt,
 
13
  ReactApp,
14
  Code,
15
  )
 
16
  from agent import Agent
17
 
18
  # Import the translated functions from the .py files
 
34
  from main import main
35
  from parseTutorial import parseTutorial
36
  from streamlitDoc import streamlitDoc
 
37
  from typescript import typescript
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  def main():
40
+ """ Main function for the application. """
 
 
 
41
  # Create an agent
42
  agent = Agent(
43
  prompts={