Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,10 +17,11 @@ SF_USERNAME = os.getenv("SF_USERNAME")
|
|
| 17 |
SF_PASSWORD = os.getenv("SF_PASSWORD")
|
| 18 |
SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN")
|
| 19 |
|
|
|
|
| 20 |
|
| 21 |
# Validate Salesforce credentials
|
| 22 |
-
if not all([SF_USERNAME, SF_PASSWORD, SF_SECURITY_TOKEN )
|
| 23 |
-
raise ValueError("Missing Salesforce credentials. Set SF_USERNAME, SF_PASSWORD, SF_SECURITY_TOKEN
|
| 24 |
|
| 25 |
# Initialize Salesforce connection
|
| 26 |
try:
|
|
@@ -28,7 +29,7 @@ try:
|
|
| 28 |
username=SF_USERNAME,
|
| 29 |
password=SF_PASSWORD,
|
| 30 |
security_token=SF_SECURITY_TOKEN,
|
| 31 |
-
|
| 32 |
domain='login' # Use 'test' for sandbox
|
| 33 |
)
|
| 34 |
except Exception as e:
|
|
@@ -152,4 +153,33 @@ def process_image(image, project_name):
|
|
| 152 |
return f"Error: Failed to update Salesforce - {str(e)}", "Failure", "", "", 0
|
| 153 |
|
| 154 |
return (
|
| 155 |
-
f
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
SF_PASSWORD = os.getenv("SF_PASSWORD")
|
| 18 |
SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN")
|
| 19 |
|
| 20 |
+
API_KEY = os.getenv("API_KEY", "your-api-key-here")
|
| 21 |
|
| 22 |
# Validate Salesforce credentials
|
| 23 |
+
if not all([SF_USERNAME, SF_PASSWORD, SF_SECURITY_TOKEN ]):
|
| 24 |
+
raise ValueError("Missing Salesforce credentials. Set SF_USERNAME, SF_PASSWORD, SF_SECURITY_TOKEN in environment variables.")
|
| 25 |
|
| 26 |
# Initialize Salesforce connection
|
| 27 |
try:
|
|
|
|
| 29 |
username=SF_USERNAME,
|
| 30 |
password=SF_PASSWORD,
|
| 31 |
security_token=SF_SECURITY_TOKEN,
|
| 32 |
+
|
| 33 |
domain='login' # Use 'test' for sandbox
|
| 34 |
)
|
| 35 |
except Exception as e:
|
|
|
|
| 153 |
return f"Error: Failed to update Salesforce - {str(e)}", "Failure", "", "", 0
|
| 154 |
|
| 155 |
return (
|
| 156 |
+
f"Success: Milestone: {milestone}, Completion: {percent_complete}%",
|
| 157 |
+
"Success",
|
| 158 |
+
milestone,
|
| 159 |
+
f"Confidence Score: {confidence_score}",
|
| 160 |
+
percent_complete
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
except Exception as e:
|
| 164 |
+
return f"Error: {str(e)}", "Failure", "", "", 0
|
| 165 |
+
|
| 166 |
+
# Gradio interface for testing
|
| 167 |
+
with gr.Blocks(css=".gradio-container {background-color: #f0f4f8; font-family: Arial;} .title {color: #2c3e50; font-size: 24px; text-align: center;}") as demo:
|
| 168 |
+
gr.Markdown("<h1 class='title'>Construction Milestone Detector</h1>")
|
| 169 |
+
project_name = gr.Textbox(label="Project Name", placeholder="Enter project name (e.g., My House or Site-123)")
|
| 170 |
+
image_input = gr.Image(type="filepath", label="Upload Construction Site Photo (JPG/PNG, ≤ 20MB)")
|
| 171 |
+
submit_button = gr.Button("Process Image")
|
| 172 |
+
output_text = gr.Textbox(label="Result")
|
| 173 |
+
upload_status = gr.Textbox(label="Upload Status")
|
| 174 |
+
milestone = gr.Textbox(label="Detected Milestone")
|
| 175 |
+
confidence = gr.Textbox(label="Confidence Score")
|
| 176 |
+
progress = gr.Slider(0, 100, label="Completion Percentage", interactive=False, value=0)
|
| 177 |
+
|
| 178 |
+
submit_button.click(
|
| 179 |
+
fn=process_image,
|
| 180 |
+
inputs=[image_input, project_name],
|
| 181 |
+
outputs=[output_text, upload_status, milestone, confidence, progress]
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
# Launch the Gradio app
|
| 185 |
+
demo.launch()
|