acecalisto3 commited on
Commit
47aeb6f
·
verified ·
1 Parent(s): 9e66234

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -12
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
- # ... (previous code)
 
 
 
 
336
 
337
- if st.button("Build & Deploy"):
338
- token = st.text_input("Enter your Hugging Face token:", type="password")
339
- generated_code, project_path = generate_app(st.session_state["user_idea"], project_name)
340
- st.write(f"Generated code: {generated_code}")
341
- if token:
342
- deploy_app_to_hf_spaces(project_name, token, generated_code)
343
- st.success("App deployed to Hugging Face Spaces!")
344
- else:
345
- st.error("Please enter a Hugging Face token to deploy the app.")
346
-
347
- if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()