Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions backend/app/logging/logging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ def setup_logger(name: str) -> logging.Logger:
datefmt="%Y-%m-%d %H:%M:%S"
)

# Console Handler
# Console Handler with UTF-8 encoding for Windows support
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(formatter)
# Enable UTF-8 encoding to handle emoji and special characters on Windows
if hasattr(console_handler.stream, 'reconfigure'):
try:
console_handler.stream.reconfigure(encoding='utf-8')
except (AttributeError, ValueError):
pass
logger.addHandler(console_handler)

# File Handler
file_handler = logging.FileHandler("app.log")
# File Handler with UTF-8 encoding
file_handler = logging.FileHandler("app.log", encoding="utf-8")
file_handler.setLevel(logging.DEBUG) # Keep detailed logs in file
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/modules/bias_detection/check_bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def check_bias(text):
"content": (f"Give bias score to the following article \n\n{text}"),
},
],
model="gemma2-9b-it",
model="llama-3.1-8b-instant",
temperature=0.3,
max_tokens=512,
)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/modules/chat/llm_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def ask_llm(question, docs):
"""

response = client.chat.completions.create(
model="gemma2-9b-it",
model="llama-3.1-8b-instant",
messages=[
{"role": "system", "content": "Use only the context to answer."},
{"role": "user", "content": prompt},
Expand Down
4 changes: 2 additions & 2 deletions backend/app/modules/facts_check/llm_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def run_claim_extractor_sdk(state):
),
},
],
model="gemma2-9b-it",
model="llama-3.1-8b-instant",
temperature=0.3,
max_tokens=512,
)
Expand Down Expand Up @@ -128,7 +128,7 @@ def run_fact_verifier_sdk(search_results):
),
},
],
model="gemma2-9b-it",
model="llama-3.1-8b-instant",
temperature=0.3,
max_tokens=256,
)
Expand Down
33 changes: 21 additions & 12 deletions backend/app/modules/facts_check/web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,24 @@


def search_google(query):
results = requests.get(
f"https://www.googleapis.com/customsearch/v1?key={GOOGLE_SEARCH}&cx=f637ab77b5d8b4a3c&q={query}"
)
res = results.json()
first = {}
first["title"] = res["items"][0]["title"]
first["link"] = res["items"][0]["link"]
first["snippet"] = res["items"][0]["snippet"]

return [
first,
]
try:
results = requests.get(
f"https://www.googleapis.com/customsearch/v1?key={GOOGLE_SEARCH}&cx=f637ab77b5d8b4a3c&q={query}"
)
res = results.json()
Comment thread
ashi2004 marked this conversation as resolved.

# Check if the response contains 'items' (successful search)
if "items" not in res:
# Handle error responses from Google API
error_msg = res.get("error", {}).get("message", "Unknown error")
raise ValueError(f"Google API Error: {error_msg}")

first = {}
first["title"] = res["items"][0]["title"]
first["link"] = res["items"][0]["link"]
first["snippet"] = res["items"][0]["snippet"]
Comment thread
ashi2004 marked this conversation as resolved.

return [first]
except Exception as e:
print(f"Search Google Error: {e}")
raise
2 changes: 1 addition & 1 deletion backend/app/modules/langgraph_nodes/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# Init once
groq_llm = ChatGroq(
model="gemma2-9b-it",
model="llama-3.1-8b-instant",
temperature=0.0,
max_tokens=10,
)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/modules/langgraph_nodes/sentiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def run_sentiment_sdk(state):
),
},
],
model="gemma2-9b-it",
model="llama-3.1-8b-instant",
temperature=0.2,
max_tokens=3,
)
Expand Down
15 changes: 9 additions & 6 deletions backend/app/utils/fact_check_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,39 @@ def run_fact_check_pipeline(state):
result = run_claim_extractor_sdk(state)

if state.get("status") != "success":
logger.error("Claim extraction failed.")
logger.error("Claim extraction failed.")
return [], "Claim extraction failed."
Comment thread
ashi2004 marked this conversation as resolved.

# Step 1: Extract claims
raw_output = result.get("verifiable_claims", "")
claims = re.findall(r"^[\*\-•]\s+(.*)", raw_output, re.MULTILINE)
claims = [claim.strip() for claim in claims if claim.strip()]
logger.info(f"🧠 Extracted claims: {claims}")
logger.info(f"Extracted claims: {claims}")

if not claims:
return [], "No verifiable claims found."

# Step 2: Search each claim with polite delay
search_results = []
for claim in claims:
logger.info(f"\n🔍 Searching for claim: {claim}")
logger.info(f"Searching for claim: {claim}")
try:
results = search_google(claim)
if results:
results[0]["claim"] = claim
search_results.append(results[0])
logger.info(f"Found result: {results[0]['title']}")
logger.info(f"Found result: {results[0]['title']}")
else:
logger.warning(f"⚠️ No search result for: {claim}")
logger.warning(f"No search result for: {claim}")
except Exception as e:
logger.error(f"Search failed for: {claim} -> {e}")
logger.error(f"Search failed for: {claim} -> {e}")

if not search_results:
logger.error("All claim searches failed or returned no results.")
return [], "All claim searches failed or returned no results."

# Step 3: Verify facts using LLM
logger.info(f"Verifying {len(search_results)} claims using LLM...")
final = run_fact_verifier_sdk(search_results)
logger.info("Fact-checking pipeline completed successfully.")
return final.get("verifications", []), None
6 changes: 3 additions & 3 deletions frontend/app/analyze/loading/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import ThemeToggle from "@/components/theme-toggle";
import axios from "axios";

// const backend_url = process.env.NEXT_PUBLIC_API_URL;
const backend_url = process.env.NEXT_PUBLIC_API_URL;
Comment thread
ashi2004 marked this conversation as resolved.



Expand Down Expand Up @@ -74,10 +74,10 @@ export default function LoadingPage() {

try {
const [processRes, biasRes] = await Promise.all([
axios.post("https://thunder1245-perspective-backend.hf.space/api/process", {
axios.post(`${backend_url}/api/process`, {
url: storedUrl,
}),
axios.post("https://thunder1245-perspective-backend.hf.space/api/bias", {
axios.post(`${backend_url}/api/bias`, {
url: storedUrl,
}),
]);
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/analyze/results/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Badge } from "@/components/ui/badge";
import BiasMeter from "@/components/bias-meter";
import axios from "axios";

// const backend_url = process.env.NEXT_PUBLIC_API_URL;
const backend_url = process.env.NEXT_PUBLIC_API_URL;

/**
* Renders the article analysis page with summary, perspectives, fact checks, bias meter, AI chat, and sources.
Expand Down Expand Up @@ -85,7 +85,7 @@ export default function AnalyzePage() {
setMessages(newMessages);
setMessage("");

const res = await axios.post("https://thunder1245-perspective-backend.hf.space/api/chat", {
const res = await axios.post(`${backend_url}/api/chat`, {
message: message,
});
const data = res.data;
Expand Down