springwater commited on
Commit
ca1bd19
Β·
verified Β·
1 Parent(s): 2bb8654

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -12
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
- response = openai.ChatCompletion.create(
27
 
28
- model="gpt-4-turbo-preview",
29
- messages=[
30
- {"role": "system", "content": "You are a helpful assistant."},
31
- {"role": "user", "content": f"Summarize this: {contents}"}
32
- ],
33
- headers={
34
- "Content-Type": "application/json",
35
- "Authorization": f"Bearer {OPENAI_API_KEY}"
36
- }
37
- )
38
- return response.choices[0].message['content'].strip()
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(