Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -42,6 +42,27 @@ def get_damaged_object_estimates(damage_description):
|
|
42 |
|
43 |
return response
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
# Streamlit interface
|
47 |
st.title("Disaster Damage Cost Estimator")
|
@@ -54,7 +75,7 @@ if st.button("Get Estimated Costs"):
|
|
54 |
if damage_description:
|
55 |
with st.spinner("Fetching cost estimates..."):
|
56 |
# Call the function to get estimates
|
57 |
-
estimated_costs = get_damaged_object_estimates(damage_description)
|
58 |
|
59 |
if estimated_costs:
|
60 |
st.success("Here are the estimated costs:")
|
|
|
42 |
|
43 |
return response
|
44 |
|
45 |
+
def postprocess_message_text(api_response):
|
46 |
+
"""
|
47 |
+
Extracts and formats the message content from the API response JSON.
|
48 |
+
|
49 |
+
Args:
|
50 |
+
api_response (str): JSON string from the API response.
|
51 |
+
|
52 |
+
Returns:
|
53 |
+
str: Formatted message content.
|
54 |
+
"""
|
55 |
+
# Parse the JSON response
|
56 |
+
response = json.loads(api_response)
|
57 |
+
|
58 |
+
# Extract the content from the choices
|
59 |
+
message_content = response["choices"][0]["message"]["content"]
|
60 |
+
|
61 |
+
# Clean the message content (remove unnecessary escape characters)
|
62 |
+
formatted_content = message_content.replace("\\n", "\n")
|
63 |
+
|
64 |
+
return formatted_content
|
65 |
+
|
66 |
|
67 |
# Streamlit interface
|
68 |
st.title("Disaster Damage Cost Estimator")
|
|
|
75 |
if damage_description:
|
76 |
with st.spinner("Fetching cost estimates..."):
|
77 |
# Call the function to get estimates
|
78 |
+
estimated_costs = postprocess_message_text(get_damaged_object_estimates(damage_description))
|
79 |
|
80 |
if estimated_costs:
|
81 |
st.success("Here are the estimated costs:")
|