五个 AI API 可自动解决你的日常问题

开发 前端 人工智能
让我们利用当今的人工智能技术实现手动工作的自动化。现在可以使用我们最喜欢的编程语言 Python 来完成校对文档、创作艺术或在 Google 中搜索答案等任务。

让我们利用当今的人工智能技术实现手动工作的自动化。现在可以使用我们最喜欢的编程语言 Python 来完成校对文档、创作艺术或在 Google 中搜索答案等任务。

在本文中,我将分享 5 个可以帮助自动化解决我们日常问题的 AI API。

现在,让我们开始吧。

01、图像生成人工智能

想要将您的想象变成现实,那么,您可能会对使用图像生成 AI API 感兴趣。该工具可让您将文本转换为美丽的艺术作品。

Getimg.ai 提供了这样一个 API,每月最多可生成 100 个免费图像。

请查看下面的 API 代码来尝试一下。

在这里获取您的 API

# AI Image Generation
# pip install requests
import requests
import base64
def generate_image(access_token, prompt):
    url = "https://api.getimg.ai/v1/stable-diffusion/text-to-image"
    headers = {"Authorization": "Bearer {}".format(access_token)}
    data = {
            "model": "stable-diffusion-v1-5",
            "prompt": prompt,
            "negative_prompt": "Disfigured, cartoon, blurry",
            "width": 512,
            "height": 512,
            "steps": 25,
            "guidance": 7.5,
            "seed": 42,
            "scheduler": "dpmsolver++",
            "output_format": "jpeg",
        }
    response = requests.post(url, headers=headers, data=data)
    image_string = response.content
    image_bytes = base64.decodebytes(image_string)
    with open("AI_Image.jpeg", "wb") as f:
        f.write(image_bytes)
if __name__ == "__main__":
    api_key = "YOUR_API_KEY"
    prompt = "a photo of a cat dressed as a pirate"
    image_bytes = generate_image(api_key, prompt)

02、人工智能校对员

需要人工智能校对器来纠正文本或文档中的语法和拼写错误,然后,使用下面的 API,它为您提供免费的 API 访问权限,并允许您使用强大的语法检查人工智能技术来修复您的文本。

在这里获取您的 API

# AI Proofreading
# pip install requests
import requests
def Proofreader(text):
    api_key = "YOUR_API_KEY"
    url = 'https://api.sapling.ai/api/v1/edits'
    data = {
        'key': api_key,
        'text': text,
        'session_id': 'Test Document UUID',
        'advanced_edits': {
            'advanced_edits': True,
        },
    }
    response = requests.post(url, json=data)
    resp_json = response.json()
    edits = resp_json['edits']
    print("Corrections: ", edits)
if __name__ == '__main__':
    Proofreader("I are going to the store, She don't likes pizza")

03、人工智能文本转语音

借助 Google Cloud 的文本转语音 AI 技术,您可以将文本转换为逼真的声音。您可以灵活地选择各种选项,例如,语言、音调、人们的声音等等。

最重要的是,Google 提供免费的 API 供您使用。

在这里获取您的 API

# AI Text to Speech
# pip install google-cloud-texttospeech
# pip install playsound
import io
import os
from google.cloud import texttospeech
import playsound
# Set the path to your credentials JSON file
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "credentials.json"
def Text_to_Speech(text):
    client = texttospeech.TextToSpeechClient()
    # Set the language code and the voice name.
    language_code = "en-US"
    voice_name = "en-US-Wavenet-A"
    # Create a request to synthesize speech.
    r = texttospeech.types.SynthesizeSpeechRequest()
    r.text = text
    r.voice = texttospeech.types.VoiceSelectionParams(
        language_code=language_code, name=voice_name)
    # Set the audio encoding.
    r.audio_encoding = texttospeech.types.AudioEncoding.MP3
    # Get the response from the API.
    response = client.synthesize_speech(r)
    # Save the audio to a file.
    with io.open("audio.mp3", "wb") as f:
        f.write(response.audio_content)
    # Play the audio.
    playsound.playsound("audio.mp3", True)
if __name__ == "__main__":
    text = input("Enter the text: ")
    Text_to_Speech(text)

04、聊天机器人人工智能

如果您正在寻找类似于 chatGPT 的聊天机器人,您可以使用 OpenAI API。我在下面提供了一些代码,演示如何使用 GPT 3.5 在 Python 中轻松创建个性化聊天机器人。

# ChatGPT AI
# pip install openai
import os
import openai
def ask(prompt):
  response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
      {
        "role": "user",
        "content": prompt
      }
    ],
    temperature=1,
    max_tokens=256,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
  )


  print("Ans: ", response)
if __name__ == "__main__":
    ask("Python or JavaScript?")

05、人工智能识别

您是否需要将扫描文档转换为文本或从图像或扫描 PDF 中提取文本?您可以使用以下 OCR AI 技术从任何类型的图像中提取文本。

下面的 API 利用了 Google Cloud Vision AI 技术,该技术擅长检测和分析图像中的文本。

在这里获取您的 API

# AI OCR
# pip install google-cloud-vision
from google.cloud import vision
from google.cloud.vision import types
import os
# Set the path to your credentials JSON file
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "credentials.json"
def OCR(img_path):
    client = vision.ImageAnnotatorClient()
    with open(img_path, 'rb') as image_file:
        content = image_file.read()
    image = types.Image(content=content)
    response = client.text_detection(image=image)
    texts = response.text_annotations
    if texts:
        return texts[0].description
    else:
        return "No text found in the image."
if __name__ == "__main__":
    image_path = "photo.jpg"
    print(OCR(image_path))

最后的想法

在自动化工作方面,人工智能的能力非常出色。我希望这篇文章能为您提供一些有用的信息。如果您觉得有帮助,请分享给您的朋友,也许能够帮助到他。

最后,感谢您的阅读,编程愉快!

责任编辑:华轩 来源: web前端开发
相关推荐

2023-04-18 10:27:15

CIO技术债务

2024-03-27 14:35:09

自动验证工具

2022-09-16 09:11:30

C++代码编程

2020-09-01 07:58:34

API漏洞黑客

2020-04-22 10:27:39

人工智能技术安全

2022-04-06 10:09:17

云服务云计算

2020-04-22 10:52:44

AI人工智能算法

2022-10-09 14:50:44

Python脚本

2024-04-15 14:20:35

边缘AI人工智能ENIAC计算机

2022-08-29 18:34:46

Pythonsubprocess系统

2022-01-19 17:25:01

人工智能机器学习

2022-01-19 13:24:21

人工智能机器学习AI

2023-04-17 16:21:20

JavaScriot前端开发

2012-04-25 08:59:04

云计算

2020-02-14 10:49:57

交通物联网IOT

2023-04-26 16:42:01

2021-11-12 10:19:00

CIOIT自动化战略

2023-09-07 15:11:44

2023-05-15 15:46:08

可持续建筑智能建筑

2009-08-24 10:37:11

Silverlight
点赞
收藏

51CTO技术栈公众号