acecalisto3 commited on
Commit
6592a3f
1 Parent(s): 67cab5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py CHANGED
@@ -3,10 +3,52 @@ import os
3
  from dotenv import load_dotenv
4
  from supplemental import EnhancedAIAgent, ProjectConfig
5
  from json import JSONDecodeError # Add this line to import JSONDecodeError
 
 
 
 
6
 
7
  # Load environment variables
8
  load_dotenv()
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Initialize EnhancedAIAgent
11
  agent = EnhancedAIAgent(
12
  name="WebDevMaster",
 
3
  from dotenv import load_dotenv
4
  from supplemental import EnhancedAIAgent, ProjectConfig
5
  from json import JSONDecodeError # Add this line to import JSONDecodeError
6
+ from transformers import pipeline
7
+
8
+ class JSONDecodeError(Exception):
9
+ pass
10
 
11
  # Load environment variables
12
  load_dotenv()
13
 
14
+ class JSONDecodeError(Exception):
15
+ pass
16
+
17
+ def generate_project_config(project_description):
18
+ generator = pipeline('text-generation', model='gpt2')
19
+
20
+ prompt = f"Generate a project configuration for the following project description: {project_description}\n\n{{"
21
+
22
+ try:
23
+ response = generator(prompt, max_length=500, num_return_sequences=1)
24
+ generated_text = response[0]['generated_text']
25
+
26
+ # Extract the JSON part
27
+ json_start = generated_text.index('{')
28
+ json_end = generated_text.rindex('}') + 1
29
+ config_str = generated_text[json_start:json_end]
30
+
31
+ config = json.loads(config_str)
32
+ return config
33
+ except JSONDecodeError as e:
34
+ st.error(f"Error decoding JSON: {str(e)}")
35
+ return None
36
+ except Exception as e:
37
+ st.error(f"An error occurred: {str(e)}")
38
+ return None
39
+
40
+ st.title("Project Configuration Generator")
41
+
42
+ project_description = st.text_area("Enter your project description:")
43
+
44
+ if st.button("Generate Configuration"):
45
+ if project_description:
46
+ config = generate_project_config(project_description)
47
+ if config:
48
+ st.json(config)
49
+ else:
50
+ st.warning("Please enter a project description.")
51
+
52
  # Initialize EnhancedAIAgent
53
  agent = EnhancedAIAgent(
54
  name="WebDevMaster",