Skip to content

ssikder2/PollyGlot---AI-Language-Translation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Language Translation App

A React-based application that provides real-time language translation powered by Anthropic's Claude API and deployed using Cloudflare Workers.

Overview

This application leverages the powerful language capabilities of Claude, Anthropic's AI model, to provide accurate and natural-sounding translations across multiple languages. The backend is implemented using Cloudflare Workers for efficient, globally distributed processing.

Features

  • Real-time language translation
  • Support for multiple languages
  • Serverless architecture using Cloudflare Workers
  • Integration with Anthropic's Claude API
  • Modern React-based user interface

Technical Stack

  • Frontend: React (Create React App)
  • Backend: Cloudflare Workers
  • AI Provider: Anthropic Claude API

Getting Started

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn
  • Cloudflare Workers account
  • Anthropic API key

[Previous sections remain the same until Installation]

Installation

  1. Clone the repository:
git clone [your-repo-url]
cd ai-translation-app
  1. Install frontend dependencies:
npm install
  1. Set up environment variables: Create a .env file in the root directory:
REACT_APP_WORKER_URL=your-worker-url
ANTHROPIC_API_KEY=your-anthropic-api-key

Cloudflare Worker Setup

  1. Install Wrangler CLI globally:
npm install -g wrangler
  1. Create a wrangler.toml file in your worker directory:
name = "translation-worker"
main = "src/worker.js"
compatibility_date = "2023-01-01"

[vars]
ANTHROPIC_API_KEY = "your-api-key"
  1. Deploy your worker:
wrangler publish

Development

To run the application locally:

  1. Start the React development server:
npm start

Access the app at http://localhost:3000

  1. For local worker development:
wrangler dev

Building for Production

  1. Create a production build:
npm run build
  1. Test the production build locally:
npm install -g serve
serve -s build

API Integration

The application uses two main APIs:

  1. Cloudflare Worker API
  • Handles request routing and API key security
  • Manages rate limiting and caching
  • Proxies requests to Anthropic's API
  1. Anthropic Claude API
  • Provides AI-powered translation capabilities
  • Handles natural language processing
  • Supports multiple language pairs

Usage

  1. Select source and target languages from the dropdown menus
  2. Enter or paste text in the source language
  3. Click "Translate" or wait for automatic translation
  4. View the translated text in the target language field

Error Handling

The application includes comprehensive error handling for:

  • Network connectivity issues
  • API rate limiting
  • Invalid input validation
  • Service unavailability

Performance Optimization

  • Implements request debouncing
  • Caches frequent translations
  • Uses worker-side caching for API responses
  • Optimizes bundle size for production

Security Considerations

  • API keys are stored securely in worker environment
  • Implements CORS policies
  • Rate limiting per user/IP
  • Input sanitization

Monitoring and Logging

  • Worker analytics via Cloudflare dashboard
  • Error tracking and reporting
  • Usage metrics and translation statistics

About

React, Cloudflare Workers | Anthropic Claude API | Translate Any Message From English to a Foreign Language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors