import streamlit as st import requests import json import os import logging # Set up logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Define fact_check_statement function here... def fact_check_statement(query, api_key): url = "https://api.wordlift.io/fact-check/score" payload = json.dumps({"query": query}) headers = { "Content-Type": "application/json", "Accept": "application/json", "Authorization": "Key " + api_key, } try: response = requests.request("POST", url, headers=headers, data=payload) logger.info( f"Request made to API: {url} with payload: {payload} and headers: {headers}" ) if response.status_code == 200: return response.json() else: logger.error( f"API request failed with status code {response.status_code} and response: {response.text}" ) return { "error": f"Failed to get response from the fact-checking API. Status code: {response.status_code}" } except Exception as e: logger.error(f"Exception during API request: {e}") return {"error": f"Exception during API request: {str(e)}"} # Page config st.set_page_config( page_title="AI Fact-Checking by WordLift", page_icon="fav-ico.png", layout="wide", initial_sidebar_state="collapsed", menu_items={ 'Get Help': 'https://wordlift.io/book-a-demo/', 'About': "# This is a demo app for AI Fact-Checking" } ) # Sidebar st.sidebar.image("logo-wordlift.png") st.sidebar.markdown(""" - ✅ AI Assistance with Immediate Fact Verification - ✅ Prevention of AI-Generated Misinformation """) # Main content with st.form(key='my_form'): text_input = st.text_area(label='Enter a statement for fact-checking') submit_button = st.form_submit_button(label='Check Claim') if submit_button and text_input: api_key = os.environ.get('WL_KEY', 'default_key') # Use a default or handle the case where the key is not set api_response = fact_check_statement(text_input, api_key) if "error" not in api_response: # Access the fields directly from api_response claim_reviewed = api_response.get("claimReviewed", "N/A") review_rating = api_response.get("reviewRating", {}) rating_value = review_rating.get("ratingValue", "N/A") alternate_name = review_rating.get("alternateName", "N/A") # Extract the alternateName review_body = api_response.get("reviewBody", "N/A") # Display the results if rating_value.isdigit(): st.progress(int(rating_value) / 5, "Fact-checking in progress.") else: st.write("Rating Value: ", rating_value) st.write(f"**Review Body**: {review_body}") # Create a two-column layout col1, col2 = st.columns(2) # Use the metric widget to display the rating and alternate name col1.metric("Rating", rating_value) col2.metric("Verdict", alternate_name) #with st.expander("Here is the final JSON-LD"): # st.json(api_response) # Display the entire JSON-LD data else: st.error("Error in fact-checking: " + api_response['error'])