Update app.py
Browse files
app.py
CHANGED
@@ -130,80 +130,7 @@ CONCLUSION: I am [XX]% confident this company is [industry description] which is
|
|
130 |
possibilities.append(poss3_match.group(1).strip())
|
131 |
|
132 |
# Extract conclusion
|
133 |
-
conclusion_match = re.search(r'CONCLUSION:(.*?)
|
134 |
-
except Exception as e:
|
135 |
-
print(f"Error getting NAICS classification: {str(e)}")
|
136 |
-
return {
|
137 |
-
"naics_code": "000000",
|
138 |
-
"reasoning": f"Error analyzing company: {str(e)}"
|
139 |
-
}
|
140 |
-
|
141 |
-
def find_naics_code(api_key, company_name, company_description):
|
142 |
-
"""Main function to find NAICS code that will be called by Gradio"""
|
143 |
-
if not api_key or not company_name:
|
144 |
-
return "Please provide both API key and company name."
|
145 |
-
|
146 |
-
try:
|
147 |
-
# Initialize Gemini API
|
148 |
-
model = initialize_gemini(api_key)
|
149 |
-
|
150 |
-
# Search for NAICS candidates
|
151 |
-
naics_candidates = google_search_naics(company_name)
|
152 |
-
|
153 |
-
# Get classification
|
154 |
-
if not naics_candidates:
|
155 |
-
result = get_naics_classification(model, company_name, company_description, [])
|
156 |
-
else:
|
157 |
-
result = get_naics_classification(model, company_name, company_description, naics_candidates)
|
158 |
-
|
159 |
-
# Format the output
|
160 |
-
output = f"## NAICS Code for {company_name}\n\n"
|
161 |
-
output += f"**NAICS Code:** {result['naics_code']}\n\n"
|
162 |
-
output += f"**Reasoning:**\n{result['reasoning']}\n\n"
|
163 |
-
|
164 |
-
# Add possibilities section
|
165 |
-
if 'possibilities' in result and result['possibilities']:
|
166 |
-
output += f"**Possible Classifications:**\n\n"
|
167 |
-
for i, possibility in enumerate(result['possibilities'], 1):
|
168 |
-
output += f"{i}. {possibility}\n\n"
|
169 |
-
|
170 |
-
# Add conclusion
|
171 |
-
if 'conclusion' in result and result['conclusion']:
|
172 |
-
output += f"**Conclusion:**\n{result['conclusion']}\n\n"
|
173 |
-
|
174 |
-
if naics_candidates:
|
175 |
-
output += f"**Candidate NAICS Codes Found from Google:**\n{', '.join(naics_candidates)}"
|
176 |
-
|
177 |
-
return output
|
178 |
-
|
179 |
-
except Exception as e:
|
180 |
-
return f"Error: {str(e)}"
|
181 |
-
|
182 |
-
# Create Gradio Interface
|
183 |
-
with gr.Blocks(title="NAICS Code Finder") as app:
|
184 |
-
gr.Markdown("# NAICS Code Finder")
|
185 |
-
gr.Markdown("This app helps you find the appropriate NAICS code for a company based on its name and description.")
|
186 |
-
|
187 |
-
with gr.Row():
|
188 |
-
with gr.Column():
|
189 |
-
api_key = gr.Textbox(label="Google Gemini API Key", placeholder="Enter your Gemini API key here", type="password")
|
190 |
-
company_name = gr.Textbox(label="Company Name", placeholder="Enter the company name")
|
191 |
-
company_description = gr.Textbox(label="Company Description", placeholder="Enter a brief description of the company", lines=5)
|
192 |
-
|
193 |
-
submit_btn = gr.Button("Find NAICS Code")
|
194 |
-
|
195 |
-
with gr.Column():
|
196 |
-
output = gr.Markdown(label="Result")
|
197 |
-
|
198 |
-
submit_btn.click(
|
199 |
-
fn=find_naics_code,
|
200 |
-
inputs=[api_key, company_name, company_description],
|
201 |
-
outputs=output
|
202 |
-
)
|
203 |
-
|
204 |
-
if __name__ == "__main__":
|
205 |
-
app.launch()
|
206 |
-
, response_text, re.DOTALL | re.IGNORECASE)
|
207 |
conclusion = conclusion_match.group(1).strip() if conclusion_match else "No conclusion provided."
|
208 |
|
209 |
# Extract final NAICS code from conclusion
|
@@ -225,7 +152,9 @@ if __name__ == "__main__":
|
|
225 |
print(f"Error getting NAICS classification: {str(e)}")
|
226 |
return {
|
227 |
"naics_code": "000000",
|
228 |
-
"reasoning": f"Error analyzing company: {str(e)}"
|
|
|
|
|
229 |
}
|
230 |
|
231 |
def find_naics_code(api_key, company_name, company_description):
|
@@ -251,8 +180,18 @@ def find_naics_code(api_key, company_name, company_description):
|
|
251 |
output += f"**NAICS Code:** {result['naics_code']}\n\n"
|
252 |
output += f"**Reasoning:**\n{result['reasoning']}\n\n"
|
253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
if naics_candidates:
|
255 |
-
output += f"**Candidate NAICS Codes Found:**\n{', '.join(naics_candidates)}"
|
256 |
|
257 |
return output
|
258 |
|
|
|
130 |
possibilities.append(poss3_match.group(1).strip())
|
131 |
|
132 |
# Extract conclusion
|
133 |
+
conclusion_match = re.search(r'CONCLUSION:(.*?)$', response_text, re.DOTALL | re.IGNORECASE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
conclusion = conclusion_match.group(1).strip() if conclusion_match else "No conclusion provided."
|
135 |
|
136 |
# Extract final NAICS code from conclusion
|
|
|
152 |
print(f"Error getting NAICS classification: {str(e)}")
|
153 |
return {
|
154 |
"naics_code": "000000",
|
155 |
+
"reasoning": f"Error analyzing company: {str(e)}",
|
156 |
+
"possibilities": [],
|
157 |
+
"conclusion": "Error in analysis"
|
158 |
}
|
159 |
|
160 |
def find_naics_code(api_key, company_name, company_description):
|
|
|
180 |
output += f"**NAICS Code:** {result['naics_code']}\n\n"
|
181 |
output += f"**Reasoning:**\n{result['reasoning']}\n\n"
|
182 |
|
183 |
+
# Add possibilities section
|
184 |
+
if 'possibilities' in result and result['possibilities']:
|
185 |
+
output += f"**Possible Classifications:**\n\n"
|
186 |
+
for i, possibility in enumerate(result['possibilities'], 1):
|
187 |
+
output += f"{i}. {possibility}\n\n"
|
188 |
+
|
189 |
+
# Add conclusion
|
190 |
+
if 'conclusion' in result and result['conclusion']:
|
191 |
+
output += f"**Conclusion:**\n{result['conclusion']}\n\n"
|
192 |
+
|
193 |
if naics_candidates:
|
194 |
+
output += f"**Candidate NAICS Codes Found from Google:**\n{', '.join(naics_candidates)}"
|
195 |
|
196 |
return output
|
197 |
|