Spaces:
Running
Running
Commit
·
4dd1c50
1
Parent(s):
8a0a25e
remove: js
Browse files
app.py
CHANGED
@@ -200,12 +200,17 @@ class TranscriptProcessor:
|
|
200 |
print("No agenda found in any description tags.")
|
201 |
return
|
202 |
|
|
|
|
|
203 |
prompt = (
|
204 |
-
f"Given the speaker mapping {self.speaker_mapping}, agenda:\n{agenda}, and the transcript: {self.formatted_transcript}\n\n"
|
205 |
"Some speaker names in the mapping might have spelling errors or be incomplete."
|
|
|
|
|
206 |
"Please correct the names based on the agenda. Return the corrected mapping in JSON format as "
|
207 |
"{'spk_0': 'Correct Name', 'spk_1': 'Correct Name', ...}."
|
208 |
"You should only update the name if the name sounds very similar, or there is a good spelling overlap/ The Speaker Introduction matches the description of the Talk from Agends. If the name is totally unrelated, keep the original name."
|
|
|
209 |
)
|
210 |
|
211 |
client = OpenAI()
|
@@ -254,7 +259,7 @@ class TranscriptProcessor:
|
|
254 |
self.formatted_transcript = "\n".join(formatted_segments)
|
255 |
|
256 |
except requests.exceptions.RequestException as e:
|
257 |
-
print(f"
|
258 |
except Exception as e:
|
259 |
print(f"Error correcting speaker mapping: {str(e)}")
|
260 |
|
@@ -447,12 +452,34 @@ In the URL, make sure that after RSID there is ? and then rest of the fields are
|
|
447 |
)
|
448 |
|
449 |
response = completion.choices[0].message
|
450 |
-
|
451 |
-
|
|
|
|
|
452 |
url = args.get("url", None)
|
453 |
if url:
|
454 |
transcript_processor.correct_speaker_mapping_with_agenda(url)
|
455 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
else:
|
457 |
return "No URL provided for correcting speaker names."
|
458 |
|
@@ -493,39 +520,40 @@ def create_chat_interface():
|
|
493 |
flex-grow: 1 !important;
|
494 |
}
|
495 |
"""
|
496 |
-
js = """
|
497 |
-
function createIframeHandler() {
|
498 |
-
let iframe = document.getElementById('link-frame');
|
499 |
-
if (!iframe) {
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
}
|
510 |
-
|
511 |
-
document.addEventListener('click', function (event) {
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
});
|
524 |
-
|
525 |
-
return 'Iframe handler initialized';
|
526 |
-
}
|
527 |
-
"""
|
528 |
-
|
|
|
529 |
chatbot = gr.Chatbot(
|
530 |
elem_id="chatbot_box",
|
531 |
layout="bubble",
|
|
|
200 |
print("No agenda found in any description tags.")
|
201 |
return
|
202 |
|
203 |
+
print(self.speaker_mapping)
|
204 |
+
|
205 |
prompt = (
|
206 |
+
f"Given the original speaker mapping {self.speaker_mapping}, agenda:\n{agenda}, and the transcript: {self.formatted_transcript}\n\n"
|
207 |
"Some speaker names in the mapping might have spelling errors or be incomplete."
|
208 |
+
"Remember that the content in agenda is accurate and transcript can have errors so prioritize the spellings and names in the agenda content."
|
209 |
+
"If the speaker name and introduction is similar to the agenda, update the speaker name in the mapping."
|
210 |
"Please correct the names based on the agenda. Return the corrected mapping in JSON format as "
|
211 |
"{'spk_0': 'Correct Name', 'spk_1': 'Correct Name', ...}."
|
212 |
"You should only update the name if the name sounds very similar, or there is a good spelling overlap/ The Speaker Introduction matches the description of the Talk from Agends. If the name is totally unrelated, keep the original name."
|
213 |
+
"You should always include all the speakers in the mapping from the original mapping, even if you don't update their names. i.e if there are 4 speakers in original mapping, new mapping should have 4 speakers always, ignore all the other spekaers in the agenda. I REPEAT DO NOT ADD OTHER NEW SPEAKERS IN THE MAPPING."
|
214 |
)
|
215 |
|
216 |
client = OpenAI()
|
|
|
259 |
self.formatted_transcript = "\n".join(formatted_segments)
|
260 |
|
261 |
except requests.exceptions.RequestException as e:
|
262 |
+
print(f" ching agenda from URL: {str(e)}")
|
263 |
except Exception as e:
|
264 |
print(f"Error correcting speaker mapping: {str(e)}")
|
265 |
|
|
|
452 |
)
|
453 |
|
454 |
response = completion.choices[0].message
|
455 |
+
messages.append(response)
|
456 |
+
|
457 |
+
if response.tool_calls:
|
458 |
+
args = eval(response.tool_calls[0].function.arguments)
|
459 |
url = args.get("url", None)
|
460 |
if url:
|
461 |
transcript_processor.correct_speaker_mapping_with_agenda(url)
|
462 |
+
corrected_speaker_mapping = transcript_processor.speaker_mapping
|
463 |
+
function_call_result_message = {
|
464 |
+
"role": "tool",
|
465 |
+
"content": json.dumps(
|
466 |
+
{
|
467 |
+
"speaker_mapping": f"Corrected Speaker Mapping is: {corrected_speaker_mapping}\n, All speakers should be addressed via this mapping. The next message should be comparing old speaker names (do not use spk_0, spk_1, use the old names) and corrected speaker names.",
|
468 |
+
}
|
469 |
+
),
|
470 |
+
"name": response.tool_calls[0].function.name,
|
471 |
+
"tool_call_id": response.tool_calls[0].id,
|
472 |
+
}
|
473 |
+
|
474 |
+
# messages.append(response.choices[0]["message"])
|
475 |
+
messages.append(function_call_result_message)
|
476 |
+
completion_payload = {"model": "gpt-4o-mini", "messages": messages}
|
477 |
+
# print("messages", messages[3])
|
478 |
+
response = client.chat.completions.create(**completion_payload)
|
479 |
+
# print("no error here")
|
480 |
+
|
481 |
+
return response.choices[0].message.content
|
482 |
+
|
483 |
else:
|
484 |
return "No URL provided for correcting speaker names."
|
485 |
|
|
|
520 |
flex-grow: 1 !important;
|
521 |
}
|
522 |
"""
|
523 |
+
# js = """
|
524 |
+
# function createIframeHandler() {
|
525 |
+
# let iframe = document.getElementById('link-frame');
|
526 |
+
# if (!iframe) {
|
527 |
+
# iframe = document.createElement('iframe');
|
528 |
+
# iframe.id = 'link-frame';
|
529 |
+
# iframe.style.position = 'absolute';
|
530 |
+
# iframe.style.width = '1px';
|
531 |
+
# iframe.style.height = '1px';
|
532 |
+
# iframe.style.right = '-100px';
|
533 |
+
# iframe.style.bottom = '-100px';
|
534 |
+
# iframe.style.display = 'none'; // Hidden initially
|
535 |
+
# document.body.appendChild(iframe);
|
536 |
+
# }
|
537 |
+
|
538 |
+
# document.addEventListener('click', function (event) {
|
539 |
+
# var link = event.target.closest('a');
|
540 |
+
# if (link && link.href) {
|
541 |
+
# try {
|
542 |
+
# iframe.src = link.href;
|
543 |
+
# iframe.style.display = 'block'; // Show iframe on link click
|
544 |
+
# event.preventDefault();
|
545 |
+
# console.log('Opening link in iframe:', link.href);
|
546 |
+
# } catch (error) {
|
547 |
+
# console.error('Failed to open link in iframe:', error);
|
548 |
+
# }
|
549 |
+
# }
|
550 |
+
# });
|
551 |
+
|
552 |
+
# return 'Iframe handler initialized';
|
553 |
+
# }
|
554 |
+
# """
|
555 |
+
|
556 |
+
with gr.Blocks(fill_height=True, fill_width=True, css=css) as demo:
|
557 |
chatbot = gr.Chatbot(
|
558 |
elem_id="chatbot_box",
|
559 |
layout="bubble",
|