Giter Site home page Giter Site logo

michaeloo0 / chatgpt-doc-translator Goto Github PK

View Code? Open in Web Editor NEW
114.0 7.0 26.0 80 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.81% Dockerfile 5.19%

chatgpt-doc-translator's Introduction

Welcome to chat with me

[email protected]

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 =# if got other org than personal
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."

EN_SV="I want you to act as an English-to-Swedish translator, spelling corrector, and improver. I will send you English content, and you will translate it into Swedish 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. I want you to convert imperial to metric system."

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 - It will translate the content and save the translated text into a file, you can specify a file folder variable in env. as FILE_FOLDER = save-file

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"'

bash - return the translated text to the terminal directly.

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

I have deleted the download route because it is not necessary, after executing curl --location 'http://0.0.0.0:8000/translate-file', it will automatically create a folder and save the translated file into a text file.

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"'




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

chatgpt-doc-translator's People

Contributors

dannythunder avatar michaeloo0 avatar stefanoamorelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

chatgpt-doc-translator's Issues

Cant process files!

{"detail":"Unsupported file type: application/octet-stream"} is the output of curl, tested both doc and docx files, where can put my hands on?

Api key won't parse correctly

There is a bug in interact_llm.py where the api key is parsed openai.api_key = os.environ['OPENAI_API_KEY'].

I've no experience in python lang, but looking at temperature=float(os.environ['TEMPERATURE']) seeing the [' '] i suspect it's not being parsed as a string.

I changed to [" "] and it worked.

Creating a pull request with some minor changes to the readme.

.env

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

.env
这个要怎么操作,小白不太懂这里啥意思

请问怎么POST 文件翻译

MyCode/openai/chatgpt-doc-translator']
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: Started reloader process [5030] using StatReload
INFO: Started server process [5036]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: 127.0.0.1:51187 - "GET / HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51187 - "GET /favicon.ico HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51187 - "GET / HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51202 - "GET / HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51350 - "POST / HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51350 - "POST //translate HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51360 - "POST /translate HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51379 - "POST /translate HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51396 - "POST /translate HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51403 - "POST /translate HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51403 - "POST / HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51411 - "POST /translate HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51414 - "GET /translate HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51414 - "GET / HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51434 - "POST /translate HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51439 - "POST / HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:51439 - "POST / HTTP/1.1" 404 Not Found

The program gets stucked at this point and cannot process the file. Some idea?

curl --location --verbose --include 'http://0.0.0.0:8000/translate'
--form 'api_type=open_ai'
--form 'translate_type=en_es'
--form 'file=@"/Users/uriarecio/Documents/Working/Translator/text_to_translate.pdf"'

  • Trying 0.0.0.0:8000...
  • Connected to 0.0.0.0 (127.0.0.1) port 8000

POST /translate HTTP/1.1
Host: 0.0.0.0:8000
User-Agent: curl/8.4.0
Accept: /
Content-Length: 50412
Content-Type: multipart/form-data; boundary=------------------------pQN4F3R81W5n9cohd4rZaV

  • We are completely uploaded and fine

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.