cyberandy commited on
Commit
6363df7
Β·
1 Parent(s): eef03e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -35,12 +35,16 @@ if st.button("Analyze"):
35
 
36
  # Display JSON response
37
  st.json(response)
38
-
39
- # Additional visual representation & analysis based on API response.
40
- # You will need to adjust this part based on the actual structure of the API response.
41
  try:
42
- M = response["analyze"][0]["M"]
43
- T = response["analyze"][0]["T"]
 
 
 
 
 
 
44
 
45
  # Display traffic light system
46
  if M == 2 and T == 2:
@@ -49,8 +53,8 @@ if st.button("Analyze"):
49
  st.write("🟑 Content is partly relevant/helpful")
50
  else:
51
  st.write("πŸ”΄ Content is not relevant")
52
- except KeyError:
53
- st.error("Invalid API response format. Unable to extract M and T values.")
 
54
  else:
55
- st.warning("Please provide all inputs!")
56
-
 
35
 
36
  # Display JSON response
37
  st.json(response)
38
+
 
 
39
  try:
40
+ # Check if `response["analyze"]` is a string and parse it if true
41
+ analyze_data = response["analyze"]
42
+ if isinstance(analyze_data, str):
43
+ analyze_data = json.loads(analyze_data)
44
+
45
+ # Extract M and T values
46
+ M = analyze_data[0]["M"]
47
+ T = analyze_data[0]["T"]
48
 
49
  # Display traffic light system
50
  if M == 2 and T == 2:
 
53
  st.write("🟑 Content is partly relevant/helpful")
54
  else:
55
  st.write("πŸ”΄ Content is not relevant")
56
+ except (KeyError, IndexError, ValueError) as e:
57
+ st.error(f"Error extracting analysis results: {str(e)}")
58
+ st.error("Please check the API response format and adapt the code accordingly.")
59
  else:
60
+ st.warning("Please provide all inputs!")