Spaces:
Sleeping
Sleeping
Update inference.py
Browse files- inference.py +13 -21
inference.py
CHANGED
@@ -196,41 +196,33 @@ class CricketCommentator(nn.Module):
|
|
196 |
|
197 |
# -------------------- PIPELINE --------------------
|
198 |
|
199 |
-
def summarize_commentary(commentary, client):
|
200 |
-
|
201 |
🔧 Final Optimized Prompt (Prompt-Engineered):
|
202 |
-
|
203 |
You are a professional cricket commentary editor.
|
204 |
You will receive raw cricket commentary text. It may contain grammar errors, unclear phrasing, or inconsistent tone.
|
205 |
-
|
206 |
Your task is to:
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
If no boundary (four/six) is mentioned, do not add one.
|
213 |
-
|
214 |
-
Maintain proper punctuation and clarity for TTS (Text-to-Speech) delivery.
|
215 |
|
216 |
Output only the cleaned commentary. No extra text.
|
217 |
Input:
|
218 |
{commentary}
|
219 |
-
|
220 |
Output:
|
221 |
"""
|
222 |
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
chat_completion = client.chat.completions.create(
|
227 |
messages=[{"role": "user", "content": prompt}],
|
228 |
model="llama-3.1-8b-instant"
|
229 |
)
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
|
|
|
|
234 |
|
235 |
def text_to_speech(text, output_path, speed=1.3):
|
236 |
raw_path = "raw_commentary.wav"
|
|
|
196 |
|
197 |
# -------------------- PIPELINE --------------------
|
198 |
|
199 |
+
def summarize_commentary(commentary, client, video_duration, tts_speed):
|
200 |
+
prompt = f"""
|
201 |
🔧 Final Optimized Prompt (Prompt-Engineered):
|
|
|
202 |
You are a professional cricket commentary editor.
|
203 |
You will receive raw cricket commentary text. It may contain grammar errors, unclear phrasing, or inconsistent tone.
|
|
|
204 |
Your task is to:
|
205 |
+
- Rewrite it as a concise, broadcast-style commentary (1 sentence max).
|
206 |
+
- Keep it short and direct—describe the action and the outcome only. No exaggeration or filler.
|
207 |
+
- The final commentary must fit inside {(video_duration} seconds, assuming the speech rate is {tts_speed}x.
|
208 |
+
- Maintain proper punctuation and clarity for TTS (Text-to-Speech) delivery.
|
|
|
|
|
|
|
|
|
209 |
|
210 |
Output only the cleaned commentary. No extra text.
|
211 |
Input:
|
212 |
{commentary}
|
|
|
213 |
Output:
|
214 |
"""
|
215 |
|
216 |
+
chat_completion = client.chat.completions.create(
|
|
|
|
|
|
|
217 |
messages=[{"role": "user", "content": prompt}],
|
218 |
model="llama-3.1-8b-instant"
|
219 |
)
|
220 |
+
|
221 |
+
final = chat_completion.choices[0].message.content.strip()
|
222 |
+
print("="*50)
|
223 |
+
print(final)
|
224 |
+
print("="*50)
|
225 |
+
return final
|
226 |
|
227 |
def text_to_speech(text, output_path, speed=1.3):
|
228 |
raw_path = "raw_commentary.wav"
|