Bofandra commited on
Commit
a813071
·
verified ·
1 Parent(s): a7217e5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from text_generation import InferenceClient
3
+
4
+ # ✅ Choose your model (you can change this to another instruct model)
5
+ client = InferenceClient("deepseek-ai/deepseek-coder-6.7b-instruct")
6
+
7
+ # 🧠 Function to generate software architecture
8
+ def generate_software_spec(name, description, architecture, components, deployment, platform, extra):
9
+ prompt = f"""
10
+ You are a software architect assistant. Based on the following input, generate:
11
+ 1. A **Sequence Diagram** in Mermaid syntax
12
+ 2. A **Business Process Flow** in Mermaid syntax
13
+ 3. Code Snippets for each component based on the selected tech stack.
14
+
15
+ ---
16
+
17
+ App Name: {name}
18
+ Description: {description}
19
+ Architecture: {architecture}
20
+ Deployment: {deployment}
21
+ Platform: {platform}
22
+ Components & Tech Stack:
23
+ {components}
24
+ Extra requirements: {extra or "None"}
25
+
26
+ Return the result in this format:
27
+
28
+ ### Sequence Diagram (Mermaid)
29
+ ```mermaid
30
+ <sequence_diagram_here>
31
+ ```
32
+
33
+ ### Business Process Flow (Mermaid)
34
+ ```mermaid
35
+ <flowchart_here>
36
+ ```
37
+
38
+ ### Code Snippets
39
+ #### Component: <Component 1>
40
+ ```<language>
41
+ <code_here>
42
+ ```
43
+
44
+ #### Component: <Component 2>
45
+ ```<language>
46
+ <code_here>
47
+ ```
48
+ """
49
+
50
+ # Generate from model (stream=True recommended for large output)
51
+ result = ""
52
+ for chunk in client.text_generation(prompt, stream=True, max_new_tokens=1024, temperature=0.7, stop=["</s>"]):
53
+ result += chunk.token.text
54
+ return result
55
+
56
+ # 🎨 Gradio UI
57
+ with gr.Blocks() as demo:
58
+ gr.Markdown("## 🧠 AI Software Architecture Assistant")
59
+
60
+ with gr.Row():
61
+ name = gr.Textbox(label="App Name", placeholder="MyApp")
62
+ description = gr.Textbox(label="Short Description", lines=2, placeholder="A system that manages online tutoring...")
63
+
64
+ with gr.Row():
65
+ architecture = gr.Radio(["Monolithic", "Backend-Frontend"], label="Architecture Style")
66
+ deployment = gr.Radio(["Serverless", "VM"], label="Deployment Style")
67
+ platform = gr.Radio(["Web App", "Mobile App"], label="Target Platform")
68
+
69
+ components = gr.Textbox(label="Components & Tech Stack (e.g. Backend: Python + Flask, Frontend: React)", lines=4)
70
+ extra = gr.Textbox(label="Extra Requirements (optional)", lines=2)
71
+
72
+ submit = gr.Button("Generate Design")
73
+ output = gr.Markdown(label="Output")
74
+
75
+ submit.click(fn=generate_software_spec,
76
+ inputs=[name, description, architecture, components, deployment, platform, extra],
77
+ outputs=output)
78
+
79
+ demo.launch()