変更をコミット
Browse files- app.py +44 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import requests
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# 環境変数のロード
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
# OpenAI APIキーの設定
|
| 10 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
| 11 |
+
|
| 12 |
+
def generate_reply(message):
|
| 13 |
+
headers = {
|
| 14 |
+
"Authorization": f"Bearer {api_key}",
|
| 15 |
+
"Content-Type": "application/json"
|
| 16 |
+
}
|
| 17 |
+
data = {
|
| 18 |
+
"model": "gpt-4-turbo-preview",
|
| 19 |
+
"messages": [
|
| 20 |
+
{
|
| 21 |
+
"role": "user",
|
| 22 |
+
"content": message
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"temperature": 1,
|
| 26 |
+
"max_tokens": 256,
|
| 27 |
+
"top_p": 1,
|
| 28 |
+
"frequency_penalty": 0,
|
| 29 |
+
"presence_penalty": 0
|
| 30 |
+
}
|
| 31 |
+
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=data)
|
| 32 |
+
if response.status_code == 200:
|
| 33 |
+
return response.json()['choices'][0]['message']['content']
|
| 34 |
+
else:
|
| 35 |
+
return "エラーが発生しました。"
|
| 36 |
+
|
| 37 |
+
# StreamlitアプリケーションのUI
|
| 38 |
+
st.title('メール返信ジェネレーター')
|
| 39 |
+
|
| 40 |
+
user_input = st.text_area("メールの内容をここに入力してください:")
|
| 41 |
+
|
| 42 |
+
if st.button('返信を生成'):
|
| 43 |
+
reply = generate_reply(user_input)
|
| 44 |
+
st.text_area("AIによる返信:", value=reply, height=300, disabled=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
openai
|
| 3 |
+
python-dotenv
|