Spaces:
Sleeping
Sleeping
Commit
·
3df9cb1
1
Parent(s):
4efdaca
update: add UID in url and states
Browse files
app.py
CHANGED
|
@@ -333,7 +333,7 @@ def get_initial_analysis(
|
|
| 333 |
link_start = "http"
|
| 334 |
else:
|
| 335 |
link_start = "https"
|
| 336 |
-
|
| 337 |
if ct == "si": # street interview
|
| 338 |
prompt = f"""This is a transcript for a street interview. Transcript: {transcript} User ID UID: {uid}
|
| 339 |
|
|
@@ -457,6 +457,7 @@ def chat(
|
|
| 457 |
rsid,
|
| 458 |
origin,
|
| 459 |
ct,
|
|
|
|
| 460 |
) -> str:
|
| 461 |
tools = [
|
| 462 |
{
|
|
@@ -583,7 +584,12 @@ In the URL, make sure that after RSID there is ? and then rest of the fields are
|
|
| 583 |
if call_type:
|
| 584 |
# Stream the analysis for corrected call type
|
| 585 |
for content in get_initial_analysis(
|
| 586 |
-
transcript_processor,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
):
|
| 588 |
yield content
|
| 589 |
return
|
|
@@ -738,6 +744,7 @@ def create_chat_interface():
|
|
| 738 |
origin_state = gr.State()
|
| 739 |
ct_state = gr.State()
|
| 740 |
turl_state = gr.State()
|
|
|
|
| 741 |
iframe_html = "<iframe id='link-frame'></iframe>"
|
| 742 |
gr.HTML(value=iframe_html) # Add iframe to the UI
|
| 743 |
|
|
@@ -749,6 +756,7 @@ def create_chat_interface():
|
|
| 749 |
rsid,
|
| 750 |
origin,
|
| 751 |
ct,
|
|
|
|
| 752 |
):
|
| 753 |
if not transcript_processor:
|
| 754 |
bot_message = "Transcript processor not initialized."
|
|
@@ -764,6 +772,7 @@ def create_chat_interface():
|
|
| 764 |
rsid,
|
| 765 |
origin,
|
| 766 |
ct,
|
|
|
|
| 767 |
):
|
| 768 |
chat_history[-1] = (message, chunk)
|
| 769 |
yield "", chat_history
|
|
@@ -778,6 +787,7 @@ def create_chat_interface():
|
|
| 778 |
colab_id_state,
|
| 779 |
origin_state,
|
| 780 |
ct_state,
|
|
|
|
| 781 |
],
|
| 782 |
[msg, chatbot],
|
| 783 |
)
|
|
@@ -789,8 +799,10 @@ def create_chat_interface():
|
|
| 789 |
origin = request.query_params.get("origin", None)
|
| 790 |
ct = request.query_params.get("ct", None)
|
| 791 |
turl = request.query_params.get("turl", None)
|
|
|
|
|
|
|
| 792 |
|
| 793 |
-
required_params = ["cid", "rsid", "origin", "ct", "turl"]
|
| 794 |
missing_params = [
|
| 795 |
param
|
| 796 |
for param in required_params
|
|
@@ -802,15 +814,7 @@ def create_chat_interface():
|
|
| 802 |
f"Missing required parameters: {', '.join(missing_params)}"
|
| 803 |
)
|
| 804 |
chatbot_value = [(None, error_message)]
|
| 805 |
-
return [
|
| 806 |
-
chatbot_value,
|
| 807 |
-
None,
|
| 808 |
-
None,
|
| 809 |
-
None,
|
| 810 |
-
None,
|
| 811 |
-
None,
|
| 812 |
-
None,
|
| 813 |
-
]
|
| 814 |
|
| 815 |
try:
|
| 816 |
transcript_data = get_transcript_for_url(turl)
|
|
@@ -830,26 +834,19 @@ def create_chat_interface():
|
|
| 830 |
origin,
|
| 831 |
ct,
|
| 832 |
turl,
|
|
|
|
| 833 |
]
|
| 834 |
except Exception as e:
|
| 835 |
error_message = f"Error processing call_id {cid}: {str(e)}"
|
| 836 |
chatbot_value = [(None, error_message)]
|
| 837 |
-
return [
|
| 838 |
-
chatbot_value,
|
| 839 |
-
None,
|
| 840 |
-
None,
|
| 841 |
-
None,
|
| 842 |
-
None,
|
| 843 |
-
None,
|
| 844 |
-
None,
|
| 845 |
-
]
|
| 846 |
|
| 847 |
def stream_initial_analysis(
|
| 848 |
-
chatbot_value, transcript_processor, cid, rsid, origin, ct
|
| 849 |
):
|
| 850 |
if transcript_processor:
|
| 851 |
for chunk in get_initial_analysis(
|
| 852 |
-
transcript_processor, cid, rsid, origin, ct
|
| 853 |
):
|
| 854 |
chatbot_value[0] = (None, chunk)
|
| 855 |
yield chatbot_value
|
|
@@ -868,6 +865,7 @@ def create_chat_interface():
|
|
| 868 |
origin_state,
|
| 869 |
ct_state,
|
| 870 |
turl_state,
|
|
|
|
| 871 |
],
|
| 872 |
).then(
|
| 873 |
stream_initial_analysis,
|
|
@@ -878,6 +876,7 @@ def create_chat_interface():
|
|
| 878 |
colab_id_state,
|
| 879 |
origin_state,
|
| 880 |
ct_state,
|
|
|
|
| 881 |
],
|
| 882 |
outputs=[chatbot],
|
| 883 |
)
|
|
|
|
| 333 |
link_start = "http"
|
| 334 |
else:
|
| 335 |
link_start = "https"
|
| 336 |
+
print(uid)
|
| 337 |
if ct == "si": # street interview
|
| 338 |
prompt = f"""This is a transcript for a street interview. Transcript: {transcript} User ID UID: {uid}
|
| 339 |
|
|
|
|
| 457 |
rsid,
|
| 458 |
origin,
|
| 459 |
ct,
|
| 460 |
+
uid,
|
| 461 |
) -> str:
|
| 462 |
tools = [
|
| 463 |
{
|
|
|
|
| 584 |
if call_type:
|
| 585 |
# Stream the analysis for corrected call type
|
| 586 |
for content in get_initial_analysis(
|
| 587 |
+
transcript_processor,
|
| 588 |
+
call_type,
|
| 589 |
+
rsid,
|
| 590 |
+
origin,
|
| 591 |
+
call_type,
|
| 592 |
+
uid,
|
| 593 |
):
|
| 594 |
yield content
|
| 595 |
return
|
|
|
|
| 744 |
origin_state = gr.State()
|
| 745 |
ct_state = gr.State()
|
| 746 |
turl_state = gr.State()
|
| 747 |
+
uid_state = gr.State()
|
| 748 |
iframe_html = "<iframe id='link-frame'></iframe>"
|
| 749 |
gr.HTML(value=iframe_html) # Add iframe to the UI
|
| 750 |
|
|
|
|
| 756 |
rsid,
|
| 757 |
origin,
|
| 758 |
ct,
|
| 759 |
+
uid,
|
| 760 |
):
|
| 761 |
if not transcript_processor:
|
| 762 |
bot_message = "Transcript processor not initialized."
|
|
|
|
| 772 |
rsid,
|
| 773 |
origin,
|
| 774 |
ct,
|
| 775 |
+
uid,
|
| 776 |
):
|
| 777 |
chat_history[-1] = (message, chunk)
|
| 778 |
yield "", chat_history
|
|
|
|
| 787 |
colab_id_state,
|
| 788 |
origin_state,
|
| 789 |
ct_state,
|
| 790 |
+
uid_state,
|
| 791 |
],
|
| 792 |
[msg, chatbot],
|
| 793 |
)
|
|
|
|
| 799 |
origin = request.query_params.get("origin", None)
|
| 800 |
ct = request.query_params.get("ct", None)
|
| 801 |
turl = request.query_params.get("turl", None)
|
| 802 |
+
uid = request.query_params.get("uid", None)
|
| 803 |
+
print(uid)
|
| 804 |
|
| 805 |
+
required_params = ["cid", "rsid", "origin", "ct", "turl", "uid"]
|
| 806 |
missing_params = [
|
| 807 |
param
|
| 808 |
for param in required_params
|
|
|
|
| 814 |
f"Missing required parameters: {', '.join(missing_params)}"
|
| 815 |
)
|
| 816 |
chatbot_value = [(None, error_message)]
|
| 817 |
+
return [chatbot_value, None, None, None, None, None, None, None]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 818 |
|
| 819 |
try:
|
| 820 |
transcript_data = get_transcript_for_url(turl)
|
|
|
|
| 834 |
origin,
|
| 835 |
ct,
|
| 836 |
turl,
|
| 837 |
+
uid,
|
| 838 |
]
|
| 839 |
except Exception as e:
|
| 840 |
error_message = f"Error processing call_id {cid}: {str(e)}"
|
| 841 |
chatbot_value = [(None, error_message)]
|
| 842 |
+
return [chatbot_value, None, None, None, None, None, None, None]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 843 |
|
| 844 |
def stream_initial_analysis(
|
| 845 |
+
chatbot_value, transcript_processor, cid, rsid, origin, ct, uid
|
| 846 |
):
|
| 847 |
if transcript_processor:
|
| 848 |
for chunk in get_initial_analysis(
|
| 849 |
+
transcript_processor, cid, rsid, origin, ct, uid
|
| 850 |
):
|
| 851 |
chatbot_value[0] = (None, chunk)
|
| 852 |
yield chatbot_value
|
|
|
|
| 865 |
origin_state,
|
| 866 |
ct_state,
|
| 867 |
turl_state,
|
| 868 |
+
uid_state,
|
| 869 |
],
|
| 870 |
).then(
|
| 871 |
stream_initial_analysis,
|
|
|
|
| 876 |
colab_id_state,
|
| 877 |
origin_state,
|
| 878 |
ct_state,
|
| 879 |
+
uid_state,
|
| 880 |
],
|
| 881 |
outputs=[chatbot],
|
| 882 |
)
|