開発環境
Server | lightSail |
Language | Python3.11 |
Framework | Django |
DB | sqlite3 |
ローカル環境ではPythonのvenvを使用。エディタはvs codeです。
目的
思い立ったらすぐ作成できる。それがDjangoのすごいところ。まじで。アプリケーションコマンドだけでアプリが生まれる。楽しくってしょうがない。英会話アプリは実質、自然言語生成AIばかりだからコスト低いのもいい。
前回の会話アプリの時に思いついてしまったので即作成してしまった。英会話アプリ。これ、実質、めっちゃ実用的だと思われる。制御系をしっかりとやって、QAしたら、売れるんじゃないだろうか。まじで。結構な自信作。100チャレのいいところは作っていくうちに質とスキルがあがっていくのがわかるところだよね。多分、一番早く成長できる。
コード
OPENAI_API_KEY = os.environ['OPENAI_API_IMAGE_KEY']
chat_results = ""
if request.method == "POST":
form = TranscribeForm(request.POST)
if form.is_valid():
client = OpenAI(
api_key = OPENAI_API_KEY,
)
audio_file_path = settings.BASE_DIR / "uploads/english/user.wav"
audio_file= open(audio_file_path , "rb")
transcription = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
response = client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "system",
"content": """
New users come to Tsunaga
The system is an excellent teacher of English
You teach English to users who are your students
You must speak english
You speak English all the time and nothing but English
You have a variety of problems for your students
You have a lot of everyday conversation
My favorite drink is coffee and my favorite food is ramen.
I love Japan.
He likes baseball and will talk about baseball.
"""
},
{
"role": "user",
"content": transcription.text
},
],
)
text_results = response.choices[0].message.content
speech_file_path = settings.BASE_DIR / "uploads/english/system.mp3"
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input=text_results
)
response.stream_to_file(speech_file_path)
chat_results = speech_file_path
else:
form = TranscribeForm()
今回は英会話目的ということで英語教師のキャラ設定をしてみた。
生徒として扱ってくれるので、思ったより勉強になる。リアルの英会話教室に行く前より先に、このアプリでリスニングをまずは鍛えたほうがいいかも。普通に会話できます。すごすぎです。自然言語生成AI。
アプリ画面
英語の先生なんでスーツ着てます。もちろん画像生成アプリでつくった先生です。生成AIをつかっていない人はマジで焦ったほうがいいように思われる。アプリチャレンジ7回目の素人がここまでできちゃうって今までだったら絶対にありえないよ。
感想
お勉強アプリとしてもぜんぜん使用可能です。大人数同時使用できるようにはつくっていないので、それはアプリチャレンジのお砂場アプリだと思ってご容赦ください。制御系まで手を出すと、はっきりいって100アプリなんて何年もかかってしまうので。1日1アプリで考えています。
明日は、ChatGPTだらけの討論会。そのまえにチャットアプリを改修するかもしれない。LINEっぽくしようとしている途中だったので。