Spaces:
Sleeping
Sleeping
Akshayram1
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# Set up API constants
|
5 |
+
API_KEY = "YOUR_GOOGLE_FACT_CHECK_API_KEY" # Replace with your Google API key
|
6 |
+
API_URL = "https://factchecktools.googleapis.com/v1alpha1/claims:search"
|
7 |
+
|
8 |
+
# Define a function to get fact-checked data based on the claim
|
9 |
+
def fact_check_claim(claim):
|
10 |
+
params = {
|
11 |
+
"query": claim,
|
12 |
+
"key": API_KEY
|
13 |
+
}
|
14 |
+
|
15 |
+
# Request to Google Fact Check Tools API
|
16 |
+
response = requests.get(API_URL, params=params)
|
17 |
+
|
18 |
+
# Check for errors
|
19 |
+
if response.status_code == 200:
|
20 |
+
return response.json() # Parsed JSON response if successful
|
21 |
+
else:
|
22 |
+
st.error("Error: Could not retrieve data. Please try again.")
|
23 |
+
return None
|
24 |
+
|
25 |
+
# Streamlit UI setup
|
26 |
+
st.title("Fact Checker for YouTube Video Claims")
|
27 |
+
st.write("Enter a claim from a YouTube video to verify with Google Fact Check Tools API.")
|
28 |
+
|
29 |
+
# Input form for claim text
|
30 |
+
claim_text = st.text_input("Claim Text", placeholder="Enter claim text here")
|
31 |
+
|
32 |
+
if st.button("Check Claim"):
|
33 |
+
if claim_text:
|
34 |
+
# Call fact-checking function
|
35 |
+
fact_data = fact_check_claim(claim_text)
|
36 |
+
|
37 |
+
# Display results if successful
|
38 |
+
if fact_data and "claims" in fact_data:
|
39 |
+
st.success("Fact-Check Results:")
|
40 |
+
for item in fact_data["claims"]:
|
41 |
+
st.write(f"**Claim:** {item['text']}")
|
42 |
+
st.write(f"**Claimed By:** {item.get('claimant', 'Unknown')}")
|
43 |
+
st.write(f"**Claim Date:** {item.get('claimDate', 'Unknown')}")
|
44 |
+
for review in item.get("claimReview", []):
|
45 |
+
st.write(f"**Publisher:** {review['publisher']['name']}")
|
46 |
+
st.write(f"**Title:** {review['title']}")
|
47 |
+
st.write(f"**URL:** {review['url']}")
|
48 |
+
st.write(f"**Review Rating:** {review.get('textualRating', 'No rating')}")
|
49 |
+
st.write("---")
|
50 |
+
else:
|
51 |
+
st.warning("No fact-checking information found for this claim.")
|
52 |
+
else:
|
53 |
+
st.warning("Please enter a claim to check.")
|