Spaces:
Sleeping
Sleeping
openai_api_key = os.getenv("OPENAI_API_KEY")
Browse files- .gitignore +1 -0
- app.py +12 -3
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
local.json
|
app.py
CHANGED
|
@@ -2,10 +2,15 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
import pandas as pd
|
| 4 |
from openai import OpenAI
|
|
|
|
| 5 |
|
| 6 |
# 設置 OpenAI API 客戶端
|
| 7 |
-
|
| 8 |
-
openai_api_key = "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
openai_client = OpenAI(api_key=openai_api_key)
|
| 10 |
|
| 11 |
def extract_article_from_content(article_text):
|
|
@@ -77,7 +82,11 @@ def generate_new_article(lesson_words, original_article, original_word_count, ba
|
|
| 77 |
return generated_article
|
| 78 |
|
| 79 |
def load_csv(file):
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
if not df.empty:
|
| 82 |
first_row = df.iloc[0]
|
| 83 |
lesson_words = first_row['lesson_words']
|
|
|
|
| 2 |
import os
|
| 3 |
import pandas as pd
|
| 4 |
from openai import OpenAI
|
| 5 |
+
import json
|
| 6 |
|
| 7 |
# 設置 OpenAI API 客戶端
|
| 8 |
+
try:
|
| 9 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 10 |
+
except:
|
| 11 |
+
# local development from local.json
|
| 12 |
+
openai_api_key = json.load(open("local.json"))["openai_api_key"]
|
| 13 |
+
|
| 14 |
openai_client = OpenAI(api_key=openai_api_key)
|
| 15 |
|
| 16 |
def extract_article_from_content(article_text):
|
|
|
|
| 82 |
return generated_article
|
| 83 |
|
| 84 |
def load_csv(file):
|
| 85 |
+
try:
|
| 86 |
+
df = pd.read_csv(file, encoding='utf-8')
|
| 87 |
+
except:
|
| 88 |
+
df = pd.read_csv(file.name, encoding='utf-8')
|
| 89 |
+
|
| 90 |
if not df.empty:
|
| 91 |
first_row = df.iloc[0]
|
| 92 |
lesson_words = first_row['lesson_words']
|