Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import streamlit as st
|
|
| 2 |
import requests
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
from transformers import pipeline
|
| 5 |
-
|
| 6 |
import os
|
| 7 |
|
| 8 |
# OpenAI API 키 설정
|
|
@@ -41,15 +41,19 @@ def load_sentiment_model():
|
|
| 41 |
# GPT-4를 이용해 반대 관점 기사 생성 (최신 OpenAI API 방식)
|
| 42 |
def generate_article_gpt4(prompt):
|
| 43 |
try:
|
| 44 |
-
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 47 |
model="gpt-4", # GPT-4 모델 사용
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
max_tokens=512,
|
| 50 |
temperature=0.7
|
| 51 |
)
|
| 52 |
-
return response
|
| 53 |
except Exception as e:
|
| 54 |
return f"Error generating text: {e}"
|
| 55 |
|
|
|
|
| 2 |
import requests
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
from transformers import pipeline
|
| 5 |
+
import openai
|
| 6 |
import os
|
| 7 |
|
| 8 |
# OpenAI API 키 설정
|
|
|
|
| 41 |
# GPT-4를 이용해 반대 관점 기사 생성 (최신 OpenAI API 방식)
|
| 42 |
def generate_article_gpt4(prompt):
|
| 43 |
try:
|
| 44 |
+
client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 45 |
+
|
| 46 |
+
# ChatGPT API 호출
|
| 47 |
+
response = client.chat.completions.create(
|
| 48 |
model="gpt-4", # GPT-4 모델 사용
|
| 49 |
+
messages=[
|
| 50 |
+
{"role": "system", "content": "You are a helpful assistant that generates articles."},
|
| 51 |
+
{"role": "user", "content": prompt}
|
| 52 |
+
],
|
| 53 |
max_tokens=512,
|
| 54 |
temperature=0.7
|
| 55 |
)
|
| 56 |
+
return response['choices'][0]['message']['content'] # GPT의 응답 텍스트
|
| 57 |
except Exception as e:
|
| 58 |
return f"Error generating text: {e}"
|
| 59 |
|