Update app.py
Browse files
app.py
CHANGED
@@ -22,20 +22,46 @@ def get_transcript(urls):
|
|
22 |
return contents
|
23 |
|
24 |
def summarize_text(contents, OPENAI_API_KEY):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
# def summarize_text(contents):
|
41 |
# response = openai.ChatCompletion.create(
|
|
|
22 |
return contents
|
23 |
|
24 |
def summarize_text(contents, OPENAI_API_KEY):
|
25 |
+
API_URL = "https://api.openai.com/v1/chat/completions"
|
26 |
+
payload = {
|
27 |
+
"model": "gpt-4-0125-preview", # λͺ¨λΈ μ΄λ¦ νμΈ νμ
|
28 |
+
"messages": [{
|
29 |
+
"role": "system",
|
30 |
+
"content": "λΉμ μ λ΄μ©μ μμ½νλ μ±λ΄μ
λλ€."
|
31 |
+
}, {
|
32 |
+
"role": "user",
|
33 |
+
"content": f"μ νλΈ λ΄μ©μΈ '{contents}'μ λν΄ μμ½ν΄μ£ΌμΈμ."
|
34 |
+
}],
|
35 |
+
}
|
36 |
+
headers = {
|
37 |
+
"Content-Type": "application/json",
|
38 |
+
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
39 |
+
}
|
40 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
41 |
+
if response.status_code == 200:
|
42 |
+
data = response.json()
|
43 |
+
# λνν API μλ΅μμ μ μ ν λ©μμ§ μΆμΆ λ° μ λͺ
μΈ μ΄λ¦ λ°ν
|
44 |
+
return data["choices"][0]["message"]["content"], get_famous_people(lunIljin)
|
45 |
+
else:
|
46 |
+
# μ€λ₯ λ©μμ§ κ°μ
|
47 |
+
return f"μ€λ₯κ° λ°μνμ΅λλ€. μν μ½λ: {response.status_code}, λ©μμ§: {response.json().get('error', {}).get('message', 'Unknown error')}", ""
|
48 |
+
|
49 |
+
|
50 |
+
# def summarize_text(contents, OPENAI_API_KEY):
|
51 |
|
52 |
+
# response = openai.ChatCompletion.create(
|
53 |
|
54 |
+
# model="gpt-4-turbo-preview",
|
55 |
+
# messages=[
|
56 |
+
# {"role": "system", "content": "You are a helpful assistant."},
|
57 |
+
# {"role": "user", "content": f"Summarize this: {contents}"}
|
58 |
+
# ],
|
59 |
+
# headers={
|
60 |
+
# "Content-Type": "application/json",
|
61 |
+
# "Authorization": f"Bearer {OPENAI_API_KEY}"
|
62 |
+
# }
|
63 |
+
# )
|
64 |
+
# return response.choices[0].message['content'].strip()
|
65 |
|
66 |
# def summarize_text(contents):
|
67 |
# response = openai.ChatCompletion.create(
|