820nam commited on
Commit
febef4d
·
verified ·
1 Parent(s): 1ae5cf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -4,9 +4,10 @@ import matplotlib.pyplot as plt
4
  from transformers import pipeline
5
  import openai
6
  import pandas as pd
 
7
 
8
  # OpenAI API 키 설정
9
- openai.api_key = "your_openai_api_key"
10
 
11
  # 네이버 뉴스 API를 통해 실제 뉴스 기사 가져오기
12
  def fetch_naver_news(query, display=5):
@@ -42,7 +43,8 @@ def load_sentiment_model():
42
  # GPT-4를 이용해 반대 관점 기사 생성
43
  def generate_article_gpt4(prompt):
44
  try:
45
- response = openai.ChatCompletion.create(
 
46
  model="gpt-4",
47
  messages=[
48
  {"role": "system", "content": "You are a helpful assistant that generates articles."},
@@ -51,7 +53,7 @@ def generate_article_gpt4(prompt):
51
  max_tokens=512,
52
  temperature=0.7
53
  )
54
- return response['choices'][0]['message']['content']
55
  except Exception as e:
56
  return f"Error generating text: {e}"
57
 
 
4
  from transformers import pipeline
5
  import openai
6
  import pandas as pd
7
+ import os
8
 
9
  # OpenAI API 키 설정
10
+ openai.api_key = os.getenv("OPENAI_API_KEY", "your_openai_api_key")
11
 
12
  # 네이버 뉴스 API를 통해 실제 뉴스 기사 가져오기
13
  def fetch_naver_news(query, display=5):
 
43
  # GPT-4를 이용해 반대 관점 기사 생성
44
  def generate_article_gpt4(prompt):
45
  try:
46
+ client = openai.OpenAI()
47
+ response = client.chat.completions.create(
48
  model="gpt-4",
49
  messages=[
50
  {"role": "system", "content": "You are a helpful assistant that generates articles."},
 
53
  max_tokens=512,
54
  temperature=0.7
55
  )
56
+ return response.choices[0].message.content
57
  except Exception as e:
58
  return f"Error generating text: {e}"
59