In today's digital landscape, the line between fact and fiction has become increasingly blurred. The proliferation of misinformation and the ease with which content can be generated and shared have created a pressing need for tools that can help verify the accuracy of information and generate reliable content.
Enter Tathya Seva Playground — a powerful, open-source platform that leverages cutting-edge AI to verify facts and generate well-researched content. Built with Flask and powered by OpenAI's GPT-4o model through the CrewAI framework, this application demonstrates how modern AI technologies can be harnessed to create practical solutions for content verification and generation.
In this article, we'll explore how Tathya Seva Playground works, dive into its architecture, and showcase how it can be deployed and extended. Whether you're a developer looking to understand the technical implementation or a content creator interested in leveraging AI for your work, this guide offers valuable insights into the capabilities and potential of this platform.
"Tathya" is a Sanskrit word meaning "truth" or "fact," and "Seva" means "service." True to its name, Tathya Seva Playground provides a service dedicated to truth — offering tools for both fact-checking existing content and generating new, well-researched content.
Tathya Seva Playground is built with a modern stack that focuses on reliability, scalability, and developer experience. Let's break down its core components:
The application uses Flask, a lightweight Python web framework, providing a solid foundation for building RESTful APIs and serving web pages.
# app.py - Core application setup import os import logging from flask import Flask, request, jsonify, render_template from agents import ResearchCrew # Configure logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) app = Flask(__name__) app.secret_key = os.environ.get("SESSION_SECRET") # Initialize Research Crew crew = ResearchCrew() @app.route('/') def index(): return render_template('index.html')
At the heart of Tathya Seva is the CrewAI framework, which enables the creation and orchestration of specialized AI agents. Each agent has a specific role, goal, and capabilities, and they work together to deliver comprehensive results.
# agents.py - Agent orchestration from crewai import Agent, Task, Crew class ResearchCrew: def __init__(self): self.api_key = os.environ.get("OPENAI_API_KEY") if not self.api_key: raise ValueError("OpenAI API key not found in environment variables") def create_agent(self, role, goal, backstory): return Agent( role=role, goal=goal, backstory=backstory, allow_delegation=True, verbose=True, api_key=self.api_key, model="gpt-4o" # Using GPT-4o for all tasks )
The fact-checking functionality involves receiving content, analyzing it through specialized agents, and returning a veracity score with detailed explanations.
# API endpoint for fact checking @app.route('/api/fact-check', methods=['POST']) def fact_check(): try: data = request.get_json() if not data or 'content' not in data: return jsonify({'error': 'No content provided'}), 400 content = data['content'] # Run fact checking process result = crew.run_fact_check(content) return jsonify({ 'veracity_score': result['score'], 'details': result['details'] }) except Exception as e: logger.error(f"Error in fact-check endpoint: {str(e)}") return jsonify({'error': str(e)}), 500
Inside the ResearchCrew
class, the fact-checking process is implemented as follows:
def run_fact_check(self, content: str) -> dict: """Run the fact checking process using a single agent approach.""" try: # Create a single fact-checking agent for simplicity fact_checker = self.create_agent( role='Fact Checker', goal='Verify the accuracy of information and provide a detailed assessment', backstory='Expert fact checker with extensive experience in information verification' ) # Create a single task for fact checking fact_check_task = Task( description=f""" Carefully fact-check the following content: {content} Format your response as a valid JSON object with this exact structure: {{ "score": number between 0 and 100, "details": "detailed explanation of the findings" }} STRICT REQUIREMENTS: 1. Response must be ONLY the JSON object 2. No text before or after the JSON 3. Use double quotes for strings 4. Properly escape special characters """, agent=fact_checker, expected_output="Valid JSON string containing score and details" ) # Execute the task and process the result # ... (result parsing code)
The content generation feature allows users to specify a topic and receive AI-generated content that is both engaging and factually accurate.
# API endpoint for content generation @app.route('/api/generate-content', methods=['POST']) def generate_content(): try: data = request.get_json() if not data or 'topic' not in data: return jsonify({'error': 'No topic provided'}), 400 topic = data['topic'] # Generate content result = crew.generate_content(topic) return jsonify({ 'content': result['content'], 'metadata': result['metadata'] }) except Exception as e: logger.error(f"Error in generate-content endpoint: {str(e)}") return jsonify({'error': str(e)}), 500
The application features a clean, responsive UI built with Bootstrap and custom CSS. Here's a snippet of the main interface:
<!-- templates/index.html - Main application interface --> <!DOCTYPE html> <html lang="en" data-bs-theme="dark"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tathya Seva Playground - Content Management System</title> <link href="https://cdn.replit.com/agent/bootstrap-agent-dark-theme.min.css" rel="stylesheet"> <link href="/static/css/custom.css" rel="stylesheet"> </head> <body> <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <div class="container"> <a class="navbar-brand" href="/">Tathya Seva Playground</a> </div> </nav> <div class="container mt-5"> <div class="row"> <!-- Fact Checking Section --> <div class="col-md-6"> <div class="card mb-4"> <div class="card-header"> <h5 class="card-title">Fact Checking</h5> </div> <div class="card-body"> <form id="fact-check-form"> <!-- Form content --> </form> </div> </div> </div> <!-- Content Generation Section --> <div class="col-md-6"> <!-- Content form --> </div> </div> </div> </body> </html>
To run Tathya Seva Playground locally, you'll need:
Set up your environment variables:
# Required environment variables OPENAI_API_KEY='your-api-key-here' SESSION_SECRET='your-session-secret' # For Flask session management
Tathya Seva Playground can be easily deployed on Replit:
During the development of Tathya Seva Playground, we encountered and resolved several challenges that are common in AI-powered applications:
One of the main challenges was handling the sometimes unpredictable output format from AI models. We implemented a robust JSON extraction system that can reliably parse responses:
# Extract JSON using a robust approach start_idx = result_str.find('{') end_idx = result_str.rfind('}') if start_idx == -1 or end_idx == -1: logger.error("No JSON object found in response") return {"error": "Could not extract JSON from response"} json_str = result_str[start_idx:end_idx + 1] parsed_result = json.loads(json_str)
Comprehensive logging is essential for debugging AI applications. We implemented detailed logging throughout the application:
# Super detailed logging logger.debug("=== Raw Fact Check Response ===") logger.debug(f"Response type: {type(result_str)}") logger.debug(f"Response length: {len(result_str)}") logger.debug(f"First 100 characters: {repr(result_str[:100])}") logger.debug(f"Last 100 characters: {repr(result_str[-100:])}")
When working with AI models, providing clear and structured instructions is crucial. We've found that explicit formatting requirements yield the best results:
description=f""" Write an engaging article about: {topic} Format your response as a valid JSON object with this exact structure: {{ "content": "your article content here" }} STRICT REQUIREMENTS: 1. Response must be ONLY the JSON object 2. No text before or after the JSON 3. Use double quotes for strings 4. Properly escape special characters """
Tathya Seva Playground has significant potential for expansion. Here are some planned enhancements:
Tathya Seva Playground represents a powerful example of how AI can be harnessed to address real-world challenges in content verification and generation. By combining modern web technologies with advanced AI orchestration, it provides a robust platform that can be used by journalists, content creators, researchers, and anyone concerned with information accuracy.
The open-source nature of this project encourages collaboration and improvement, and we invite contributions from developers interested in enhancing its capabilities or adapting it to specialized domains.
As AI continues to evolve, tools like Tathya Seva Playground will play an increasingly important role in our information ecosystem, helping to ensure that we can navigate the complex landscape of digital content with greater confidence and clarity.
Code repository here and live demo available at Tathya Seva Playground
There are no models linked
There are no datasets linked
There are no models linked
There are no datasets linked