-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
116 lines (107 loc) · 2.4 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import click
from dotenv import load_dotenv
from icecream import ic # noqa: F401
from audio import transcribe_audio, translate_audio
from chat import start_chat
from image import generate_image
from utils import validate_options
load_dotenv()
@click.command()
@click.option(
"-v",
"--verbose",
is_flag=True,
help="Makes the error messages verbose.",
)
@click.option(
"-c",
"--chat",
is_flag=True,
help="Start an interactive chat with the AI.",
)
@click.option(
"-m",
"--model",
default="gpt-4",
help="Model name to use for chat.",
)
@click.option(
"-w",
"--whisper",
type=click.Path(exists=True),
help="Generate a transcription from an audio file.",
)
@click.option(
"-t",
"--translate",
type=click.Path(exists=True),
help=(
"Generate a translated transcription from an audio file. "
"Translates audio into English."
),
)
@click.option(
"-i",
"--image",
type=str,
help="Generate an image from a prompt.",
)
@click.option(
"-n",
"--number-of-images",
default=1,
type=int,
help=(
"Generate image(s) from a prompt. Specify the number of images to generate. "
"(Default: 1)"
),
)
@click.option(
"-f",
"--image-folder",
default="./images",
help="Folder to save the generated images. (Default: ./images)",
)
@click.option(
"-g",
"--image-model",
default="dall-e-3",
help="Model name to use for image generation. (Default: dall-e-3)",
)
@click.option(
"-s",
"--image-size",
default="1024x1024",
help="Specify the size of the images to generate (default: 1024x1024).",
)
def main(
verbose,
chat,
model,
whisper,
translate,
image,
number_of_images,
image_folder,
image_model,
image_size,
):
"""
A command-line tool for interacting with the OpenAI API.
Supports chat, audio transcription, audio translation, and image generation.
"""
validate_options(click.get_current_context())
if chat:
start_chat(model, verbose)
elif whisper:
transcribe_audio(whisper, verbose)
elif translate:
translate_audio(translate, verbose)
elif image:
generate_image(
image_model, image, number_of_images, image_folder, image_size, verbose
)
else:
click.echo(main.get_help(click.Context(main)))
if __name__ == "__main__":
main()