kanha-upadhyay commited on
Commit
e3adae4
·
1 Parent(s): 0de56cb

Refactor imports and enhance proposal generation with architecture diagram handling

Browse files
Files changed (1) hide show
  1. src/app.py +14 -7
src/app.py CHANGED
@@ -1,13 +1,14 @@
 
1
  import re
2
  import tempfile
3
- import base64
4
- import httpx
5
  from enum import Enum
 
 
 
 
 
6
  from fastapi import FastAPI, HTTPException
7
  from pydantic import BaseModel
8
- from docx import Document
9
- from docx.shared import Pt, Inches
10
- import pypandoc
11
 
12
  from src.utils import EmailClient
13
 
@@ -18,11 +19,13 @@ pypandoc.download_pandoc()
18
  template_path = "src/template.docx"
19
  DOC = Document(template_path)
20
 
 
21
  class Email(str, Enum):
22
  sukhwinder = "sukhwinder@sifars.com"
23
  munish = "munish@sifars.com"
24
  jatin = "jatin@sifars.com"
25
 
 
26
  class ProposalRequest(BaseModel):
27
  project_name: str
28
  project_overview: str
@@ -41,10 +44,12 @@ class ProposalRequest(BaseModel):
41
  architecture_diagram: str
42
  recipient_email: Email
43
 
 
44
  async def generate_proposal(data: dict):
45
 
46
  mermaid_code = data.get("architecture_diagram", "")
47
  architecture_diagram_path = None
 
48
 
49
  if mermaid_code.strip():
50
  graphbytes = mermaid_code.encode("utf8")
@@ -57,13 +62,15 @@ async def generate_proposal(data: dict):
57
  response = await client.get(url)
58
  response.raise_for_status()
59
 
60
- with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
 
 
61
  temp_file.write(response.content)
62
  architecture_diagram_path = temp_file.name
63
  except httpx.HTTPError as e:
64
  raise HTTPException(
65
  status_code=500,
66
- detail=f"Failed to generate architecture diagram: {str(e)}"
67
  )
68
 
69
  for para in DOC.paragraphs:
 
1
+ import base64
2
  import re
3
  import tempfile
 
 
4
  from enum import Enum
5
+
6
+ import httpx
7
+ import pypandoc
8
+ from docx import Document
9
+ from docx.shared import Inches, Pt
10
  from fastapi import FastAPI, HTTPException
11
  from pydantic import BaseModel
 
 
 
12
 
13
  from src.utils import EmailClient
14
 
 
19
  template_path = "src/template.docx"
20
  DOC = Document(template_path)
21
 
22
+
23
  class Email(str, Enum):
24
  sukhwinder = "sukhwinder@sifars.com"
25
  munish = "munish@sifars.com"
26
  jatin = "jatin@sifars.com"
27
 
28
+
29
  class ProposalRequest(BaseModel):
30
  project_name: str
31
  project_overview: str
 
44
  architecture_diagram: str
45
  recipient_email: Email
46
 
47
+
48
  async def generate_proposal(data: dict):
49
 
50
  mermaid_code = data.get("architecture_diagram", "")
51
  architecture_diagram_path = None
52
+ mermaid_code.replace("\n", "")
53
 
54
  if mermaid_code.strip():
55
  graphbytes = mermaid_code.encode("utf8")
 
62
  response = await client.get(url)
63
  response.raise_for_status()
64
 
65
+ with tempfile.NamedTemporaryFile(
66
+ delete=False, suffix=".png"
67
+ ) as temp_file:
68
  temp_file.write(response.content)
69
  architecture_diagram_path = temp_file.name
70
  except httpx.HTTPError as e:
71
  raise HTTPException(
72
  status_code=500,
73
+ detail=f"Failed to generate architecture diagram: {str(e)}",
74
  )
75
 
76
  for para in DOC.paragraphs: