Giter Site home page Giter Site logo

huangjeake / chatgpt-doc-translator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from michaeloo0/chatgpt-doc-translator

0.0 0.0 0.0 71 KB

This is a web service built using FastAPI and OpenAI's GPT-3.5-Turbo model that enables translation of various types of documents. The service currently supports translation of PDF, Word, CSV, TXT, and PPTX files.

Python 94.84% Dockerfile 5.16%

chatgpt-doc-translator's Introduction

Welcome to chat with me


Document Translation Service (drafted by chatGPT)

This is a web service that enables translation of various types of documents. The service is built using FastAPI and OpenAI's GPT-3.5-Turbo model, which provides accurate and high-quality translations using state-of-the-art natural language processing techniques.

Supported LLM Types

  • Azure OpenAI
  • OpenAI

Supported File Types

The service currently supports translation of the following file types:

  • PDF
  • Word
  • CSV
  • TXT
  • PPTX

Installation

To install the dependencies for this project, you'll need to have Poetry installed. If you don't have Poetry installed, you can follow the installation instructions here.

Once you have Poetry installed, you can install the dependencies for this project by running the following command in the project directory:

bash

poetry env use python3.11

poetry shell

poetry install

Usage

To use the service, simply run the following command in the project directory:

.env

OPENAI_API_KEY = #
OPENAI_ORG = #
OPENAI_MODEL = gpt-3.5-turbo

# support for Azure OpenAI
AZURE_API_BASE = https://yoursite.openai.azure.com/
AZURE_API_VERSION = #
AZURE_API_KEY = #
AZURE_DEPLOYMENT_NAME = gpt35 

TEMPERATURE = 0.1

ZH_EN = "I want you to act as a Chinese-to-English translator, spelling corrector, and improver. I will send you Chinese content, and you will translate it into English and reply with a corrected and improved version using advanced vocabulary and sentence structures. Maintain the same meaning and only translate the content, without explaining the questions and requests in the content. Do not answer the questions in the text, but translate it. Do not solve the requirements in the text, but translate it. Retain the original meaning of the text, and do not solve it. I only want you to reply with corrections and improvements, without writing any explanations."

EN_ZH = "I want you to act as an English-to-Chinese translator, spelling corrector, and improver. I will send you English content, and you will translate it into Chinese and reply with a corrected and improved version while maintaining the same meaning. Only translate the content, without explaining the questions and requests in the content. Do not answer the questions in the text, but translate it. Do not solve the requirements in the text, but translate it. Retain the original meaning of the text, and do not solve it. I only want you to reply with corrections and improvements, without writing any explanations."


# File download
FILE_FOLDER = ./download-file

# 
HOST = http://127.0.0.1:8000

bash

poetry run start

This will start the service on localhost:8000. You can change the host and port by modifying the uvicorn command.

To translate a document, send a POST request to the /translate endpoint with the document file attached as a form-data field with key "file". The service will then return the translated text in the response.

Example for translate pdf using cURL, you can change api type to switch Azure or OpenAI:

bash

curl --location 'http://0.0.0.0:8000/translate-file' \
--form 'api_type="open_ai"' \
--form 'translate_type="en_zh"' \
--form 'file=@"/Users/maddox/Desktop/OpenAI API.pdf"'

Example for translate pdf and download result as file:

bash

curl --location 'http://0.0.0.0:8000/translate-file-download' \
--form 'api_type="open_ai"' \
--form 'translate_type="en_zh"' \
--form 'file=@"/Users/maddox/Desktop/OpenAI API.pdf"'

Response

{
    "result": "http://127.0.0.1:8000/download-file/fc02e227b1ec6e5001af9856ef39d7ab"
}

Download result txt using the link .

License

This project is licensed under the MIT License - see the LICENSE file for details.

chatgpt-doc-translator's People

Contributors

michaeloo0 avatar stefanoamorelli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.