Spaces:
Runtime error
Runtime error
seawolf2357
commited on
Commit
β’
06e7007
1
Parent(s):
df4a546
Update app.py
Browse files
app.py
CHANGED
@@ -99,7 +99,6 @@ async def get_best_available_transcript(video_id):
|
|
99 |
return None
|
100 |
|
101 |
async def get_video_comments(video_id):
|
102 |
-
|
103 |
try:
|
104 |
comments = []
|
105 |
response = youtube_service.commentThreads().list(part='snippet', videoId=video_id, maxResults=100).execute()
|
@@ -123,9 +122,9 @@ async def generate_reply(comment, transcript):
|
|
123 |
μμ±λ κΈμ λ§μ§λ§μ λ°λμ μΈμΏλ§κ³Ό OpenFreeAI λΌκ³ μμ μ λ°νλΌ.
|
124 |
"""
|
125 |
prompt = f"{system_prompt}\nλκΈ: {comment}\nλΉλμ€ μλ§: {transcript}"
|
126 |
-
response =
|
127 |
-
if response
|
128 |
-
return response
|
129 |
except Exception as e:
|
130 |
logging.error(f"Error generating reply: {e}")
|
131 |
return "λ΅λ³μ μμ±ν μ μμ΅λλ€."
|
@@ -136,11 +135,14 @@ async def create_thread_and_send_reply(message, video_id, comment, reply):
|
|
136 |
embed = discord.Embed(description=f"**λκΈ**: {comment[0]}\n**λ΅κΈ**: {reply}")
|
137 |
await thread.send(embed=embed)
|
138 |
webhook_data = {"video_id": video_id, "replies": [{"comment": comment[0], "reply": reply, "comment_id": comment[1]}]}
|
139 |
-
await send_webhook_data(webhook_data)
|
140 |
-
except
|
141 |
-
|
142 |
-
|
143 |
-
|
|
|
|
|
|
|
144 |
data_json = json.dumps(data)
|
145 |
for i in range(0, len(data_json), MAX_CHUNK_SIZE):
|
146 |
chunk = data_json[i:i+MAX_CHUNK_SIZE]
|
|
|
99 |
return None
|
100 |
|
101 |
async def get_video_comments(video_id):
|
|
|
102 |
try:
|
103 |
comments = []
|
104 |
response = youtube_service.commentThreads().list(part='snippet', videoId=video_id, maxResults=100).execute()
|
|
|
122 |
μμ±λ κΈμ λ§μ§λ§μ λ°λμ μΈμΏλ§κ³Ό OpenFreeAI λΌκ³ μμ μ λ°νλΌ.
|
123 |
"""
|
124 |
prompt = f"{system_prompt}\nλκΈ: {comment}\nλΉλμ€ μλ§: {transcript}"
|
125 |
+
response = hf_client.text_generation(prompt=prompt, max_length=150)
|
126 |
+
if response:
|
127 |
+
return response["generated_text"].strip()
|
128 |
except Exception as e:
|
129 |
logging.error(f"Error generating reply: {e}")
|
130 |
return "λ΅λ³μ μμ±ν μ μμ΅λλ€."
|
|
|
135 |
embed = discord.Embed(description=f"**λκΈ**: {comment[0]}\n**λ΅κΈ**: {reply}")
|
136 |
await thread.send(embed=embed)
|
137 |
webhook_data = {"video_id": video_id, "replies": [{"comment": comment[0], "reply": reply, "comment_id": comment[1]}]}
|
138 |
+
await send_webhook_data(webhook_data, self.session)
|
139 |
+
except discord.HTTPException as e:
|
140 |
+
if e.code == 160004:
|
141 |
+
logging.error("A thread has already been created for this message")
|
142 |
+
else:
|
143 |
+
logging.error(f"Error in thread creation and reply sending: {e}")
|
144 |
+
|
145 |
+
async def send_webhook_data(data, session):
|
146 |
data_json = json.dumps(data)
|
147 |
for i in range(0, len(data_json), MAX_CHUNK_SIZE):
|
148 |
chunk = data_json[i:i+MAX_CHUNK_SIZE]
|