manabb commited on
Commit
5ccfe8a
·
verified ·
1 Parent(s): c1d6841

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -5
app.py CHANGED
@@ -4,6 +4,7 @@ from openai import OpenAI
4
  import pandas as pd
5
  from docx import Document
6
  import time
 
7
 
8
  client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
9
 
@@ -87,7 +88,59 @@ def generate_response(manual, proposal):
87
  messages=[{"role": "user", "content": prompt}],
88
  temperature=0.1
89
  )
90
- return response.choices[0].message.content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
  def loop_function(df):
93
  text = "<hr>"
@@ -143,12 +196,14 @@ def loop_function(df):
143
  if i == 1:
144
  try:
145
  text += """
146
- <div style="color: white !important; background: #006400 !important; padding: 10px; font-size: 14px;">
 
147
  """
148
- text += "<p>As per proposal, "+key + " : "+value+"<p>"
149
  rr = generate_response(manual_rules, proposal_details)
150
- text += "<h2>"+rr + "</h2>"
151
- text += "</div><hr>"
 
152
  yield text
153
  time.sleep(3)
154
  except Exception as e:
 
4
  import pandas as pd
5
  from docx import Document
6
  import time
7
+ import re
8
 
9
  client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
10
 
 
88
  messages=[{"role": "user", "content": prompt}],
89
  temperature=0.1
90
  )
91
+ return response.choices[0].message.content
92
+
93
+ def generate_html(llm_response):
94
+
95
+ #llm_response = """Status: COMPLIANT
96
+ #Severity: LOW
97
+ #Deviations: None
98
+ #Fix: None
99
+ #COMPLIANCE ANALYSIS: The proposal complies with the MANUAL requirements as it is based on a firm offer from an OEM, which is acceptable for the specified Tender Type. Since the proposal is for OEM procurement, it adheres to the guidelines that allow for a single vendor's firm offer to serve as the basis for the estimate. There are no deviations noted, and thus no corrective actions are necessary."""
100
+
101
+ # Parse key-values and analysis
102
+ data = {'Status': '', 'Severity': '', 'Fix': '', 'Deviations': '', 'Analysis': ''}
103
+ lines = llm_response.strip().splitlines()
104
+ for line in lines:
105
+ line = line.strip()
106
+ if not line:
107
+ continue
108
+ if ':' in line:
109
+ key, value = line.split(':', 1)
110
+ key = key.strip()
111
+ value = value.strip()
112
+ if key in data:
113
+ data[key] = value
114
+ elif 'COMPLIANCE ANALYSIS:' in line:
115
+ data['Analysis'] = line.split('COMPLIANCE ANALYSIS:', 1)[1].strip()
116
+ else:
117
+ data['Analysis'] += ' ' + line # Append to analysis if multi-line
118
+
119
+ #print(data) # {'Status': 'COMPLIANT', 'Severity': 'LOW', ...}
120
+ html = """
121
+
122
+ <div>
123
+ <style>
124
+ table { border-collapse: collapse; width: 100%; font-family: Arial; }
125
+ th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
126
+ th { background-color: #f2f2f2; font-weight: bold; }
127
+ tr:nth-child(even) { background-color: #f9f9f9; }
128
+ .status-compliant { color: green; font-weight: bold; }
129
+ .status-low { color: orange; }
130
+ .analysis { background-color: #f0f8ff; }
131
+ </style>
132
+ </div>
133
+
134
+ <table>
135
+ <tr><th>Status</th><td class="status-compliant">{Status}</td></tr>
136
+ <tr><th>Severity</th><td class="status-low">{Severity}</td></tr>
137
+ <tr><th>Deviations</th><td>{Deviations}</td></tr>
138
+ <tr><th>Fix</th><td>{Fix}</td></tr>
139
+ <tr><th>Analysis</th><td class="analysis">{Analysis}</td></tr>
140
+ </table>
141
+ """
142
+ return html
143
+
144
 
145
  def loop_function(df):
146
  text = "<hr>"
 
196
  if i == 1:
197
  try:
198
  text += """
199
+ <div style="color: white !important; background: #006400 !important; padding: 10px; font-size: 14px;">
200
+ <table>
201
  """
202
+ text += "<tr><td>As per proposal, "+key + " </td><td> "+value+"</td></tr>"
203
  rr = generate_response(manual_rules, proposal_details)
204
+ rr_html=generate_html(rr)
205
+ text += rr_html
206
+ text += "<hr>"
207
  yield text
208
  time.sleep(3)
209
  except Exception as e: