Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -332,18 +332,45 @@ def deploy_app_to_hf_spaces(project_name, token, generated_code):
|
|
332 |
os.remove(temp_file)
|
333 |
|
334 |
def launch_chatapp(project_path):
|
335 |
-
|
|
|
|
|
|
|
|
|
336 |
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
db.create_all() # Create the database tables if they don't exist
|
349 |
main()
|
|
|
332 |
os.remove(temp_file)
|
333 |
|
334 |
def launch_chatapp(project_path):
|
335 |
+
if st.button("Launch ChatApp"):
|
336 |
+
st.write("Launching ChatApp...")
|
337 |
+
os.chdir(project_path)
|
338 |
+
subprocess.run(["python", "app.py"])
|
339 |
+
st.write("ChatApp launched successfully!")
|
340 |
|
341 |
+
if __name__ == "__main__":
|
342 |
+
db.create_all() # Create the database tables if they don't exist
|
343 |
+
main()
|
344 |
+
|
345 |
+
def generate_app(user_idea, project_name):
|
346 |
+
# Extract key information from the user idea
|
347 |
+
summary = nlp_pipeline(user_idea, max_length=50, min_length=10)[0]["summary_text"]
|
348 |
+
|
349 |
+
# Create project directory if it doesn't exist
|
350 |
+
project_path = create_project(project_name)
|
351 |
+
|
352 |
+
# Generate code using Codex
|
353 |
+
prompt = f"Create a simple Streamlit app for the project named '{project_name}'. The app should display the following summary: '{summary}'."
|
354 |
+
generated_code = codex_pipeline(prompt)[0]['generated_text']
|
355 |
+
|
356 |
+
# Save the generated code to a file in the project directory
|
357 |
+
with open(os.path.join(project_path, "app.py"), "w") as f:
|
358 |
+
f.write(generated_code)
|
359 |
+
|
360 |
+
# Upload the file to Hugging Face Spaces
|
361 |
+
api = HfApi()
|
362 |
+
repo_id = create_repo(api, project_name)["repo_id"]
|
363 |
+
temp_file = "temp_code.py"
|
364 |
+
with open(temp_file, "w") as f:
|
365 |
+
f.write(generated_code)
|
366 |
+
api.upload_files(repo_id, [temp_file], api.api_key)
|
367 |
+
|
368 |
+
# Delete the temporary file
|
369 |
+
os.remove(temp_file)
|
370 |
+
|
371 |
+
# Launch the app
|
372 |
+
launch_chatapp(project_path)
|
373 |
+
|
374 |
+
if __name__ == "__main__":
|
375 |
db.create_all() # Create the database tables if they don't exist
|
376 |
main()
|