Spaces:
Sleeping
Sleeping
acecalisto3
commited on
Rename logx/prompts.mts to logx/prompts.py
Browse files- logx/prompts.mts +0 -38
- logx/prompts.py +340 -0
logx/prompts.mts
DELETED
@@ -1,38 +0,0 @@
|
|
1 |
-
from string import Template
|
2 |
-
|
3 |
-
def create_prompt(app_type: str, app_name: str, app_description: str, app_features: list[str], app_dependencies: list[str], app_space: str, app_tutorial: str) -> str:
|
4 |
-
"""Creates a dynamic prompt based on the provided information."""
|
5 |
-
|
6 |
-
prompt_template = Template("""
|
7 |
-
Create a $app_type app called $app_name that does the following:
|
8 |
-
$app_description
|
9 |
-
The app should have the following features:
|
10 |
-
$app_features
|
11 |
-
The app should use the following dependencies:
|
12 |
-
$app_dependencies
|
13 |
-
The app should be deployed to $app_space.
|
14 |
-
The app should have the following tutorial:
|
15 |
-
$app_tutorial
|
16 |
-
""")
|
17 |
-
|
18 |
-
return prompt_template.substitute(
|
19 |
-
app_type=app_type,
|
20 |
-
app_name=app_name,
|
21 |
-
app_description=app_description,
|
22 |
-
app_features="\n".join(app_features),
|
23 |
-
app_dependencies="\n".join(app_dependencies),
|
24 |
-
app_space=app_space,
|
25 |
-
app_tutorial=app_tutorial,
|
26 |
-
)
|
27 |
-
|
28 |
-
# Example usage:
|
29 |
-
app_type = "web app"
|
30 |
-
app_name = "MyWebApp"
|
31 |
-
app_description = "This app displays a welcome message."
|
32 |
-
app_features = ["Display a welcome message", "Show the current time"]
|
33 |
-
app_dependencies = ["Flask", "Jinja2"]
|
34 |
-
app_space = "Heroku"
|
35 |
-
app_tutorial = "1. Install dependencies.\n2. Run the app."
|
36 |
-
|
37 |
-
prompt = create_prompt(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial)
|
38 |
-
print(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List, Dict, Optional
|
2 |
+
from types import (
|
3 |
+
Code,
|
4 |
+
Prompt,
|
5 |
+
AppType,
|
6 |
+
File,
|
7 |
+
Space,
|
8 |
+
Tutorial,
|
9 |
+
App,
|
10 |
+
WebApp,
|
11 |
+
GradioApp,
|
12 |
+
StreamlitApp,
|
13 |
+
ReactApp,
|
14 |
+
Code,
|
15 |
+
)
|
16 |
+
|
17 |
+
def createLlamaPrompt(
|
18 |
+
app_type: AppType,
|
19 |
+
app_name: str,
|
20 |
+
app_description: str,
|
21 |
+
app_features: List[str],
|
22 |
+
app_dependencies: List[str],
|
23 |
+
app_space: Optional[Space] = None,
|
24 |
+
app_tutorial: Optional[Tutorial] = None,
|
25 |
+
) -> Prompt:
|
26 |
+
"""
|
27 |
+
Generates a prompt for a Llama model to create a web application.
|
28 |
+
"""
|
29 |
+
prompt = f"""
|
30 |
+
I need you to help me create a {app_type} web application.
|
31 |
+
The application name is: {app_name}
|
32 |
+
The application description is: {app_description}
|
33 |
+
The application features are: {app_features}
|
34 |
+
The application dependencies are: {app_dependencies}
|
35 |
+
The application space is: {app_space}
|
36 |
+
The application tutorial is: {app_tutorial}
|
37 |
+
Please generate the code for the application.
|
38 |
+
"""
|
39 |
+
return Prompt(prompt=prompt)
|
40 |
+
|
41 |
+
def createSpace(
|
42 |
+
app_type: AppType,
|
43 |
+
app_name: str,
|
44 |
+
app_description: str,
|
45 |
+
app_features: List[str],
|
46 |
+
app_dependencies: List[str],
|
47 |
+
app_space: Optional[Space] = None,
|
48 |
+
app_tutorial: Optional[Tutorial] = None,
|
49 |
+
) -> Space:
|
50 |
+
"""
|
51 |
+
Generates a space for a web application.
|
52 |
+
"""
|
53 |
+
space = f"""
|
54 |
+
{app_name}
|
55 |
+
{app_description}
|
56 |
+
{app_features}
|
57 |
+
{app_dependencies}
|
58 |
+
{app_space}
|
59 |
+
{app_tutorial}
|
60 |
+
"""
|
61 |
+
return Space(space=space)
|
62 |
+
|
63 |
+
def isPythonOrGradioAppPrompt(
|
64 |
+
app_type: AppType,
|
65 |
+
app_name: str,
|
66 |
+
app_description: str,
|
67 |
+
app_features: List[str],
|
68 |
+
app_dependencies: List[str],
|
69 |
+
app_space: Optional[Space] = None,
|
70 |
+
app_tutorial: Optional[Tutorial] = None,
|
71 |
+
) -> Prompt:
|
72 |
+
"""
|
73 |
+
Generates a prompt to determine if a web application is a Python or Gradio application.
|
74 |
+
"""
|
75 |
+
prompt = f"""
|
76 |
+
Is the following web application a Python or Gradio application?
|
77 |
+
{app_name}
|
78 |
+
{app_description}
|
79 |
+
{app_features}
|
80 |
+
{app_dependencies}
|
81 |
+
{app_space}
|
82 |
+
{app_tutorial}
|
83 |
+
Please answer with either "Python" or "Gradio".
|
84 |
+
"""
|
85 |
+
return Prompt(prompt=prompt)
|
86 |
+
|
87 |
+
def isReactAppPrompt(
|
88 |
+
app_type: AppType,
|
89 |
+
app_name: str,
|
90 |
+
app_description: str,
|
91 |
+
app_features: List[str],
|
92 |
+
app_dependencies: List[str],
|
93 |
+
app_space: Optional[Space] = None,
|
94 |
+
app_tutorial: Optional[Tutorial] = None,
|
95 |
+
) -> Prompt:
|
96 |
+
"""
|
97 |
+
Generates a prompt to determine if a web application is a React application.
|
98 |
+
"""
|
99 |
+
prompt = f"""
|
100 |
+
Is the following web application a React application?
|
101 |
+
{app_name}
|
102 |
+
{app_description}
|
103 |
+
{app_features}
|
104 |
+
{app_dependencies}
|
105 |
+
{app_space}
|
106 |
+
{app_tutorial}
|
107 |
+
Please answer with either "Yes" or "No".
|
108 |
+
"""
|
109 |
+
return Prompt(prompt=prompt)
|
110 |
+
|
111 |
+
def isStreamlitAppPrompt(
|
112 |
+
app_type: AppType,
|
113 |
+
app_name: str,
|
114 |
+
app_description: str,
|
115 |
+
app_features: List[str],
|
116 |
+
app_dependencies: List[str],
|
117 |
+
app_space: Optional[Space] = None,
|
118 |
+
app_tutorial: Optional[Tutorial] = None,
|
119 |
+
) -> Prompt:
|
120 |
+
"""
|
121 |
+
Generates a prompt to determine if a web application is a Streamlit application.
|
122 |
+
"""
|
123 |
+
prompt = f"""
|
124 |
+
Is the following web application a Streamlit application?
|
125 |
+
{app_name}
|
126 |
+
{app_description}
|
127 |
+
{app_features}
|
128 |
+
{app_dependencies}
|
129 |
+
{app_space}
|
130 |
+
{app_tutorial}
|
131 |
+
Please answer with either "Yes" or "No".
|
132 |
+
"""
|
133 |
+
return Prompt(prompt=prompt)
|
134 |
+
|
135 |
+
def getWebApp(
|
136 |
+
app_type: AppType,
|
137 |
+
app_name: str,
|
138 |
+
app_description: str,
|
139 |
+
app_features: List[str],
|
140 |
+
app_dependencies: List[str],
|
141 |
+
app_space: Optional[Space] = None,
|
142 |
+
app_tutorial: Optional[Tutorial] = None,
|
143 |
+
) -> WebApp:
|
144 |
+
"""
|
145 |
+
Generates code for a web application.
|
146 |
+
"""
|
147 |
+
code = f"""
|
148 |
+
<!DOCTYPE html>
|
149 |
+
<html lang="en">
|
150 |
+
<head>
|
151 |
+
<meta charset="UTF-8">
|
152 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
153 |
+
<title>{app_name}</title>
|
154 |
+
</head>
|
155 |
+
<body>
|
156 |
+
<h1>{app_name}</h1>
|
157 |
+
<p>{app_description}</p>
|
158 |
+
</body>
|
159 |
+
</html>
|
160 |
+
"""
|
161 |
+
return WebApp(code=code, language="html")
|
162 |
+
|
163 |
+
def getGradioApp(
|
164 |
+
app_type: AppType,
|
165 |
+
app_name: str,
|
166 |
+
app_description: str,
|
167 |
+
app_features: List[str],
|
168 |
+
app_dependencies: List[str],
|
169 |
+
app_space: Optional[Space] = None,
|
170 |
+
app_tutorial: Optional[Tutorial] = None,
|
171 |
+
) -> GradioApp:
|
172 |
+
"""
|
173 |
+
Generates code for a Gradio application.
|
174 |
+
"""
|
175 |
+
code = f"""
|
176 |
+
import gradio as gr
|
177 |
+
|
178 |
+
def greet(name):
|
179 |
+
return f"Hello, {name}!"
|
180 |
+
|
181 |
+
demo = gr.Interface(greet, "text", "text")
|
182 |
+
|
183 |
+
if __name__ == "__main__":
|
184 |
+
demo.launch()
|
185 |
+
"""
|
186 |
+
return GradioApp(code=code, language="python")
|
187 |
+
|
188 |
+
def getReactApp(
|
189 |
+
app_type: AppType,
|
190 |
+
app_name: str,
|
191 |
+
app_description: str,
|
192 |
+
app_features: List[str],
|
193 |
+
app_dependencies: List[str],
|
194 |
+
app_space: Optional[Space] = None,
|
195 |
+
app_tutorial: Optional[Tutorial] = None,
|
196 |
+
) -> ReactApp:
|
197 |
+
"""
|
198 |
+
Generates code for a React application.
|
199 |
+
"""
|
200 |
+
code = f"""
|
201 |
+
import React from 'react';
|
202 |
+
|
203 |
+
function App() {{
|
204 |
+
return (
|
205 |
+
<div className="App">
|
206 |
+
<h1>{app_name}</h1>
|
207 |
+
<p>{app_description}</p>
|
208 |
+
</div>
|
209 |
+
);
|
210 |
+
}}
|
211 |
+
|
212 |
+
export default App;
|
213 |
+
"""
|
214 |
+
return ReactApp(code=code, language="javascript")
|
215 |
+
|
216 |
+
def getStreamlitApp(
|
217 |
+
app_type: AppType,
|
218 |
+
app_name: str,
|
219 |
+
app_description: str,
|
220 |
+
app_features: List[str],
|
221 |
+
app_dependencies: List[str],
|
222 |
+
app_space: Optional[Space] = None,
|
223 |
+
app_tutorial: Optional[Tutorial] = None,
|
224 |
+
) -> StreamlitApp:
|
225 |
+
"""
|
226 |
+
Generates code for a Streamlit application.
|
227 |
+
"""
|
228 |
+
code = f"""
|
229 |
+
import streamlit as st
|
230 |
+
|
231 |
+
st.title('{app_name}')
|
232 |
+
st.write('{app_description}')
|
233 |
+
"""
|
234 |
+
return StreamlitApp(code=code, language="python")
|
235 |
+
|
236 |
+
def parseTutorial(
|
237 |
+
app_type: AppType,
|
238 |
+
app_name: str,
|
239 |
+
app_description: str,
|
240 |
+
app_features: List[str],
|
241 |
+
app_dependencies: List[str],
|
242 |
+
app_space: Optional[Space] = None,
|
243 |
+
app_tutorial: Optional[Tutorial] = None,
|
244 |
+
) -> Tutorial:
|
245 |
+
"""
|
246 |
+
Parses a tutorial for a web application.
|
247 |
+
"""
|
248 |
+
tutorial = f"""
|
249 |
+
## {app_name} Tutorial
|
250 |
+
|
251 |
+
**Introduction**
|
252 |
+
{app_description}
|
253 |
+
|
254 |
+
**Prerequisites**
|
255 |
+
* Basic knowledge of {app_type} development
|
256 |
+
* Familiarity with {', '.join(app_dependencies)}
|
257 |
+
|
258 |
+
**Steps**
|
259 |
+
1. {app_features[0]}
|
260 |
+
2. {app_features[1]}
|
261 |
+
3. {app_features[2]}
|
262 |
+
|
263 |
+
**Conclusion**
|
264 |
+
Congratulations! You have successfully created a {app_name} application.
|
265 |
+
"""
|
266 |
+
return Tutorial(tutorial=tutorial)
|
267 |
+
|
268 |
+
def generateFiles(
|
269 |
+
app_type: AppType,
|
270 |
+
app_name: str,
|
271 |
+
app_description: str,
|
272 |
+
app_features: List[str],
|
273 |
+
app_dependencies: List[str],
|
274 |
+
app_space: Optional[Space] = None,
|
275 |
+
app_tutorial: Optional[Tutorial] = None,
|
276 |
+
) -> List[File]:
|
277 |
+
"""
|
278 |
+
Generates files for a web application.
|
279 |
+
"""
|
280 |
+
files = []
|
281 |
+
if app_type == AppType.WEB_APP:
|
282 |
+
files.append(File(name="index.html", content=getWebApp(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial).code, language="html"))
|
283 |
+
elif app_type == AppType.GRADIO_APP:
|
284 |
+
files.append(File(name="app.py", content=getGradioApp(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial).code, language="python"))
|
285 |
+
elif app_type == AppType.STREAMLIT_APP:
|
286 |
+
files.append(File(name="app.py", content=getStreamlitApp(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial).code, language="python"))
|
287 |
+
elif app_type == AppType.REACT_APP:
|
288 |
+
files.append(File(name="App.js", content=getReactApp(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial).code, language="javascript"))
|
289 |
+
return files
|
290 |
+
|
291 |
+
4. types.py
|
292 |
+
|
293 |
+
from enum import Enum
|
294 |
+
from typing import List, Dict, Optional
|
295 |
+
|
296 |
+
class Code:
|
297 |
+
def __init__(self, code: str, language: str):
|
298 |
+
self.code = code
|
299 |
+
self.language = language
|
300 |
+
|
301 |
+
class Prompt:
|
302 |
+
def __init__(self, prompt: str):
|
303 |
+
self.prompt = prompt
|
304 |
+
|
305 |
+
class AppType(Enum):
|
306 |
+
WEB_APP = "web app"
|
307 |
+
GRADIO_APP = "gradio app"
|
308 |
+
STREAMLIT_APP = "streamlit app"
|
309 |
+
REACT_APP = "react app"
|
310 |
+
|
311 |
+
class File:
|
312 |
+
def __init__(self, name: str, content: str, language: str):
|
313 |
+
self.name = name
|
314 |
+
self.content = content
|
315 |
+
self.language = language
|
316 |
+
|
317 |
+
class Space:
|
318 |
+
def __init__(self, space: str):
|
319 |
+
self.space = space
|
320 |
+
|
321 |
+
class Tutorial:
|
322 |
+
def __init__(self, tutorial: str):
|
323 |
+
self.tutorial = tutorial
|
324 |
+
|
325 |
+
class App:
|
326 |
+
def __init__(self, code: str, language: str):
|
327 |
+
self.code = code
|
328 |
+
self.language = language
|
329 |
+
|
330 |
+
class WebApp(App):
|
331 |
+
pass
|
332 |
+
|
333 |
+
class GradioApp(App):
|
334 |
+
pass
|
335 |
+
|
336 |
+
class StreamlitApp(App):
|
337 |
+
pass
|
338 |
+
|
339 |
+
class ReactApp(App):
|
340 |
+
pass
|