manabb commited on
Commit
257ceea
·
verified ·
1 Parent(s): 18bf68b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +122 -16
app.py CHANGED
@@ -1,27 +1,133 @@
1
  import gradio as gr
2
  import os
3
  from openai import OpenAI
 
 
 
 
 
4
 
5
  client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
6
 
7
- def check_compliance(file):
8
- # file is a TemporaryUploadedFile object
9
- with open(file.name, "r", encoding="utf-8") as f:
10
- content = f.read()
11
 
12
- response = client.responses.create(
13
- model="gpt-4.1-nano",
14
- input=content,
15
- temperature=0.1
16
- )
 
 
 
 
 
 
17
 
 
 
 
 
 
 
 
 
 
18
  return response.output[0].content[0].text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- gr.Interface(
21
- fn=check_compliance,
22
- inputs=gr.File(
23
- label="Upload Proposal",
24
- file_types=[".docx"]
 
 
 
 
 
 
 
 
 
 
 
 
25
  )
26
- outputs=gr.Textbox(lines=15, label="Compliance Result"),
27
- ).launch()
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import os
3
  from openai import OpenAI
4
+ import pandas as pd
5
+ from docx import Document
6
+ import time
7
+
8
+ #==== import completed
9
 
10
  client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
11
 
12
+ #====generate response function started
13
+ def generate_response(manual,proposal):
14
+ prompt = """
15
+ You are a strict compliance checker for Govt. procurement policies.
16
 
17
+ You must check whether the proposal is complying the requirements of MANUAL and then respond in the exact structured format shown below.
18
+
19
+ Format (use these exact labels):
20
+ Status: COMPLIANT or NON-COMPLIANT
21
+ Severity: HIGH or MEDIUM or LOW
22
+ Deviations: <short bullet-style description of deviations or 'None'>
23
+ Fix: <clear corrective action>
24
+
25
+ COMPLIANCE ANALYSIS: <2–4 sentences explaining reasoning>
26
+
27
+ MANUAL: {manual}
28
 
29
+ proposal: {proposal}
30
+
31
+ """
32
+ response = client.responses.create(
33
+ #model="gpt-4.1-nano",
34
+ model="gpt-5-mini",
35
+ input=prompt,
36
+ temperature=0.1
37
+ )
38
  return response.output[0].content[0].text
39
+ #===generate_response function end
40
+ #=====loop function start
41
+ def loop_function(df):
42
+ Value_of_proposal=""
43
+ Category_of_proposal=""
44
+ Tender_Type_of_proposal=""
45
+ Name_of_proposal=""
46
+ manual_rules=""
47
+ proposal_details=""
48
+ for index, row in df.iterrows():
49
+ key = str(row['Field'])
50
+ value = str(row['Value'])
51
+ i=0
52
+ proposal_details=""
53
+ manual_rules=""
54
+ if key == "File No.":
55
+ #print(f"The proposal E-File No. of Arohan is: {value}")
56
+ continue
57
+ if key == "PR No.":
58
+ #print(f"The proposal PR No. is: {value}")
59
+ continue
60
+ if key == "Value (Rs)":
61
+ #print(f"The proposal Value is: {value}")
62
+ Value_of_proposal=f"The proposal Value is {value}. \n"
63
+ continue
64
+ if key == "Category":
65
+ #print(f"The proposal Category is: {value}")
66
+ Category_of_proposal=f"The proposal Category is {value}. \n"
67
+ continue
68
+ if key == "Tender Type":
69
+ #print(f"The proposal Tender Type is: {value}")
70
+ Tender_Type_of_proposal=f"The proposal Tender Type is {value}. \n"
71
+ continue
72
+ if key == "Name of proposal":
73
+ #print(f"The proposal Name of proposal is: {value}. \n")
74
+ continue
75
+ if key == "Justification/Reason for Procurement":
76
+ #print(f"The reason for Procurement of the items is as under: {value}. \n")
77
+ continue
78
+ if key == "PQC for Open tenders":
79
+ manual_rules = PQC_rules
80
+ proposal_details= f"The Pre Qualifying Criteria (PQC) of the proposal is under: {value}. {Value_of_proposal}"
81
+ i=1
82
+ if key == "Basis of estimate":
83
+ manual_rules=manual_basis_of_estimate
84
+ proposal_details= f"The basis of estimate of the proposal is under: {value}. "
85
+ i=1
86
+ if key == "Payment Terms":
87
+ manual_rules=manual_payment_type
88
+ proposal_details=f"The Payment Terms of the proposal is {value}. "
89
+ i=1
90
+
91
+ #query = f"{key}: {value}"
92
+
93
+
94
+ if i==1:
95
+ try:
96
+ rr = generate_response(manual_rules,proposal_details)
97
+ text += rr
98
+ yield text
99
+ time.sleep(3)
100
+ continue
101
+ except Exception as e:
102
+ print(f"Error: {e} - skipping row")
103
+ continue
104
+ #======loop function completed
105
 
106
+
107
+
108
+ def check_compliance(file):
109
+ if file.name.endswith(".docx"):
110
+ df1 = extract_docx_text(file.name)
111
+ loop_function(df1)
112
+ else:
113
+ return "Unsupported file format"
114
+
115
+
116
+ #=====gradio coding
117
+
118
+ with gr.Blocks() as demo:
119
+ with gr.Row():
120
+ inputs=gr.File(
121
+ label="Upload Proposal",
122
+ file_types=[".docx"]
123
  )
124
+
125
+ out = gr.Textbox(lines=15, label="Compliance Result")
126
+
127
+ run_btn = gr.Button("Check compliance")
128
+
129
+ # Important: use queue() to enable streaming
130
+ run_btn.click(check_compliance, inputs=inp, outputs=out)
131
+
132
+ demo.queue().launch()
133
+