Spaces:
Sleeping
Sleeping
import streamlit as st | |
import requests | |
# Set up API constants | |
API_KEY = "YOUR_GOOGLE_FACT_CHECK_API_KEY" # Replace with your Google API key | |
API_URL = "https://factchecktools.googleapis.com/v1alpha1/claims:search" | |
# Define a function to get fact-checked data based on the claim | |
def fact_check_claim(claim): | |
params = { | |
"query": claim, | |
"key": API_KEY | |
} | |
# Request to Google Fact Check Tools API | |
response = requests.get(API_URL, params=params) | |
# Check for errors | |
if response.status_code == 200: | |
return response.json() # Parsed JSON response if successful | |
else: | |
st.error("Error: Could not retrieve data. Please try again.") | |
return None | |
# Streamlit UI setup | |
st.title("Fact Checker for YouTube Video Claims") | |
st.write("Enter a claim from a YouTube video to verify with Google Fact Check Tools API.") | |
# Input form for claim text | |
claim_text = st.text_input("Claim Text", placeholder="Enter claim text here") | |
if st.button("Check Claim"): | |
if claim_text: | |
# Call fact-checking function | |
fact_data = fact_check_claim(claim_text) | |
# Display results if successful | |
if fact_data and "claims" in fact_data: | |
st.success("Fact-Check Results:") | |
for item in fact_data["claims"]: | |
st.write(f"**Claim:** {item['text']}") | |
st.write(f"**Claimed By:** {item.get('claimant', 'Unknown')}") | |
st.write(f"**Claim Date:** {item.get('claimDate', 'Unknown')}") | |
for review in item.get("claimReview", []): | |
st.write(f"**Publisher:** {review['publisher']['name']}") | |
st.write(f"**Title:** {review['title']}") | |
st.write(f"**URL:** {review['url']}") | |
st.write(f"**Review Rating:** {review.get('textualRating', 'No rating')}") | |
st.write("---") | |
else: | |
st.warning("No fact-checking information found for this claim.") | |
else: | |
st.warning("Please enter a claim to check.") | |