cyberandy commited on
Commit
c207765
1 Parent(s): 44183dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -23
app.py CHANGED
@@ -67,30 +67,41 @@ if submit_button and text_input:
67
  api_key = os.environ.get('WL_KEY', 'default_key') # Use a default or handle the case where the key is not set
68
  api_response = fact_check_statement(text_input, api_key)
69
 
70
- if "error" not in api_response:
71
- # Access the fields directly from api_response
72
- claim_reviewed = api_response.get("claimReviewed", "N/A")
73
- review_rating = api_response.get("reviewRating", {})
74
- rating_value = review_rating.get("ratingValue", "N/A")
75
- alternate_name = review_rating.get("alternateName", "N/A") # Extract the alternateName
76
- review_body = api_response.get("reviewBody", "N/A")
77
 
78
- # Display the results
79
- if rating_value.isdigit():
80
- st.progress(int(rating_value) / 5, "Fact-checking in progress.")
81
- else:
82
- st.write("Rating Value: ", rating_value)
83
- st.write(f"**Review Body**: {review_body}")
84
 
85
- # Create a two-column layout
86
- col1, col2 = st.columns(2)
 
87
 
88
- # Use the metric widget to display the rating and alternate name
89
- col1.metric("Rating", rating_value)
90
- col2.metric("Verdict", alternate_name)
91
-
92
- #with st.expander("Here is the final JSON-LD"):
93
- # st.json(api_response) # Display the entire JSON-LD data
94
 
95
- else:
96
- st.error("Error in fact-checking: " + api_response['error'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  api_key = os.environ.get('WL_KEY', 'default_key') # Use a default or handle the case where the key is not set
68
  api_response = fact_check_statement(text_input, api_key)
69
 
70
+ if "error" not in api_response:
71
+ # Extract the 'response' string from api_response
72
+ response_str = api_response.get("response", "{}")
 
 
 
 
73
 
74
+ # Remove the triple backticks from the response string if they exist
75
+ response_str = response_str.strip('`')
 
 
 
 
76
 
77
+ # Parse the string as JSON
78
+ try:
79
+ inner_json = json.loads(response_str)
80
 
81
+ # Now, extract the information from inner_json as before
82
+ claim_reviewed = inner_json.get("claimReviewed", "N/A")
83
+ review_rating = inner_json.get("reviewRating", {})
84
+ rating_value = review_rating.get("ratingValue", "N/A")
85
+ alternate_name = review_rating.get("alternateName", "N/A")
86
+ review_body = inner_json.get("reviewBody", "N/A")
87
 
88
+ # Display the results
89
+ if rating_value.isdigit():
90
+ st.progress(int(rating_value) / 5, "Fact-checking in progress.")
91
+ else:
92
+ st.write("Rating Value: ", rating_value)
93
+ st.write(f"**Review Body**: {review_body}")
94
+
95
+ # Create a two-column layout
96
+ col1, col2 = st.columns(2)
97
+
98
+ # Use the metric widget to display the rating and alternate name
99
+ col1.metric("Rating", rating_value)
100
+ col2.metric("Verdict", alternate_name)
101
+
102
+ #with st.expander("Here is the final JSON-LD"):
103
+ # st.json(api_response) # Display the entire JSON-LD data
104
+ except json.JSONDecodeError as e:
105
+ st.error(f"Error decoding JSON: {e}")
106
+ else:
107
+ st.error("Error in fact-checking: " + api_response['error'])