abhidgp1978 commited on
Commit
4e19130
·
verified ·
1 Parent(s): 76f085e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -9
app.py CHANGED
@@ -3,14 +3,32 @@ import os
3
  import subprocess
4
  from transformers import pipeline
5
 
6
- # === LLM Initialization ===
7
- llm = pipeline("text2text-generation", model="google/flan-t5-base")
8
 
9
  # === Utility Functions ===
10
  def generate_with_prompt(prompt: str, max_length=400):
11
- """Generate meaningful structured text with T5 model."""
12
- result = llm(prompt, max_length=max_length, num_return_sequences=1, truncation=True, temperature=0.7, repetition_penalty=1.8, top_p=0.9)
13
- return result[0]["generated_text"].strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  def generate_requirements(user_input):
16
  # Prompt is focused purely on extracting requirements from the idea
@@ -21,7 +39,7 @@ def generate_requirements(user_input):
21
  return generate_with_prompt(prompt)
22
 
23
  def generate_architecture(requirements):
24
- # NEW: Architecture now takes Requirements as input
25
  prompt = (
26
  f"Design a high-level software architecture based on these requirements: {requirements}\n"
27
  "Include layers, APIs, and data flow as clear bullet points in a section titled '## Architecture Components'."
@@ -29,7 +47,7 @@ def generate_architecture(requirements):
29
  return generate_with_prompt(prompt)
30
 
31
  def generate_workflow(architecture):
32
- # NEW: Workflow now takes Architecture as input
33
  prompt = (
34
  f"Create a 5-phase development workflow for the following architecture: {architecture}\n"
35
  "Include: phase title, task, and deliverable for each step, titled '## Development Workflow'."
@@ -37,7 +55,7 @@ def generate_workflow(architecture):
37
  return generate_with_prompt(prompt)
38
 
39
  def generate_code_template(workflow):
40
- # NEW: Code now takes Workflow as input
41
  prompt = (
42
  f"Write a clean, commented Python code template based on this workflow: {workflow}\n"
43
  "Include classes, functions, and logical placeholders logically."
@@ -94,7 +112,8 @@ with gr.Blocks(title="FlowForge AI") as app:
94
  code_out = gr.Textbox(label="Code Template", lines=10)
95
  with gr.TabItem("Diagram"):
96
  diagram_out = gr.Textbox(label="Architecture Diagram (Mermaid Markdown)", lines=8)
97
- img_out = gr.Image(label="Architecture Diagram Visualization (If available)", visible=False) # Keep image hidden as we output markdown
 
98
 
99
  generate_btn.click(
100
  fn=generate_all,
 
3
  import subprocess
4
  from transformers import pipeline
5
 
6
+ # === LLM Initialization (REMOVED: The pipeline is now initialized inside the utility function) ===
7
+ # llm = pipeline("text2text-generation", model="google/flan-t5-base")
8
 
9
  # === Utility Functions ===
10
  def generate_with_prompt(prompt: str, max_length=400):
11
+ """
12
+ Generate meaningful structured text with T5 model.
13
+ Initializes the pipeline locally to ensure stability.
14
+ """
15
+ try:
16
+ # Initialize pipeline within the function for execution stability
17
+ llm = pipeline("text2text-generation", model="google/flan-t5-base")
18
+ result = llm(
19
+ prompt,
20
+ max_length=max_length,
21
+ num_return_sequences=1,
22
+ truncation=True,
23
+ temperature=0.7,
24
+ repetition_penalty=1.8,
25
+ top_p=0.9
26
+ )
27
+ return result[0]["generated_text"].strip()
28
+ except Exception as e:
29
+ # Provide a helpful error message if the model fails to load or execute
30
+ return f"Error during generation: {e}. Check if 'google/flan-t5-base' is available."
31
+
32
 
33
  def generate_requirements(user_input):
34
  # Prompt is focused purely on extracting requirements from the idea
 
39
  return generate_with_prompt(prompt)
40
 
41
  def generate_architecture(requirements):
42
+ # Architecture now takes Requirements as input
43
  prompt = (
44
  f"Design a high-level software architecture based on these requirements: {requirements}\n"
45
  "Include layers, APIs, and data flow as clear bullet points in a section titled '## Architecture Components'."
 
47
  return generate_with_prompt(prompt)
48
 
49
  def generate_workflow(architecture):
50
+ # Workflow now takes Architecture as input
51
  prompt = (
52
  f"Create a 5-phase development workflow for the following architecture: {architecture}\n"
53
  "Include: phase title, task, and deliverable for each step, titled '## Development Workflow'."
 
55
  return generate_with_prompt(prompt)
56
 
57
  def generate_code_template(workflow):
58
+ # Code now takes Workflow as input
59
  prompt = (
60
  f"Write a clean, commented Python code template based on this workflow: {workflow}\n"
61
  "Include classes, functions, and logical placeholders logically."
 
112
  code_out = gr.Textbox(label="Code Template", lines=10)
113
  with gr.TabItem("Diagram"):
114
  diagram_out = gr.Textbox(label="Architecture Diagram (Mermaid Markdown)", lines=8)
115
+ # img_out is no longer used for visualization, but kept for Gradio structure
116
+ img_out = gr.Image(label="Architecture Diagram Visualization (If available)", visible=False)
117
 
118
  generate_btn.click(
119
  fn=generate_all,