Spaces:
Build error
Build error
Vijayanand Sankarasubramanian commited on
Commit ·
6861834
1
Parent(s): b912529
added llm choice per method and fixed typo in anthropic model name
Browse files- app.py +28 -26
- helpers/model_utils.py +1 -1
app.py
CHANGED
|
@@ -4,42 +4,42 @@ from tools.summarize import MAPREDUCE, STUFF, summarize_podcast
|
|
| 4 |
from tools.answer_bot import answer_question
|
| 5 |
from tools.aspect_and_sentiment_extraction import extract_aspects_and_sentiment
|
| 6 |
|
| 7 |
-
def get_answer_for(user_question, transcript_file_name,
|
| 8 |
if transcript_file_name is None:
|
| 9 |
answer_text = "No Transcript Uploaded, Upload RTF File First", ""
|
| 10 |
-
elif not
|
| 11 |
answer_text = "No LLM Selected, select one"
|
| 12 |
elif not user_question:
|
| 13 |
answer_text = "Question Not Given"
|
| 14 |
else:
|
| 15 |
# Answer the user's question using the question-answering model
|
| 16 |
-
answer_text = answer_question(question=user_question, transcript_file_name=transcript_file_name, llm_choice=
|
| 17 |
|
| 18 |
return answer_text.lstrip(), transcript_file_name, llm_choice
|
| 19 |
|
| 20 |
-
def summarize(uploaded_file, transcript_file_name, summarization_method,
|
| 21 |
if transcript_file_name is None:
|
| 22 |
summary = "No Transcript Uploaded, Upload RTF File First", ""
|
| 23 |
-
elif not
|
| 24 |
summary = "No LLM Selected, select one"
|
| 25 |
elif not summarization_method:
|
| 26 |
summary = "No Summarization Method Selected , select one"
|
| 27 |
else:
|
| 28 |
# Summarize the content
|
| 29 |
-
summary = summarize_podcast(transcript_file_name=transcript_file_name, summarization_method=summarization_method, llm_choice=
|
| 30 |
|
| 31 |
return summary, transcript_file_name, summarization_method, llm_choice
|
| 32 |
|
| 33 |
-
def generate_aspects_and_sentiments(uploaded_file, transcript_file_name,
|
| 34 |
if transcript_file_name is None:
|
| 35 |
sentiment = "No Transcript Uploaded, Upload RTF File First", ""
|
| 36 |
-
elif not
|
| 37 |
sentiment = "No LLM Selected, select one"
|
| 38 |
else:
|
| 39 |
# Aspect-Based Sentiment Analysis
|
| 40 |
-
sentiment = extract_aspects_and_sentiment(transcript_file_name=transcript_file_name, llm_choice=
|
| 41 |
|
| 42 |
-
return sentiment, transcript_file_name,
|
| 43 |
|
| 44 |
def setup_rtf_file_handle(uploaded_file, transcript_file_name):
|
| 45 |
if not uploaded_file:
|
|
@@ -49,20 +49,20 @@ def setup_rtf_file_handle(uploaded_file, transcript_file_name):
|
|
| 49 |
status = "Upload Success"
|
| 50 |
return status, transcript_file_name
|
| 51 |
|
| 52 |
-
def setup_summarization_llm(choice,
|
| 53 |
set_summarization_llm(choice)
|
| 54 |
-
|
| 55 |
-
return choice,
|
| 56 |
|
| 57 |
-
def setup_sentiment_analysis_llm(choice,
|
| 58 |
set_sentiment_analysis_llm(choice)
|
| 59 |
-
|
| 60 |
-
return choice,
|
| 61 |
|
| 62 |
-
def setup_question_answer_llm(choice,
|
| 63 |
set_question_answer_llm(choice)
|
| 64 |
-
|
| 65 |
-
return choice,
|
| 66 |
|
| 67 |
def setup_summarization_method(choice, summarization_method):
|
| 68 |
summarization_method = choice
|
|
@@ -76,7 +76,9 @@ summarize_method_choices = [MAPREDUCE, STUFF]
|
|
| 76 |
with gr.Blocks() as demo:
|
| 77 |
transcript_file_name = gr.State()
|
| 78 |
summarization_method = gr.State()
|
| 79 |
-
|
|
|
|
|
|
|
| 80 |
with gr.Group("Upload RTF File"):
|
| 81 |
rtf_file = gr.File(label="Podcast Transcript RTF file")
|
| 82 |
submit_button = gr.Button("Upload File")
|
|
@@ -86,15 +88,15 @@ with gr.Blocks() as demo:
|
|
| 86 |
with gr.Row():
|
| 87 |
choice = gr.Radio(label="Summarization LLM", choices=summarization_llm_choices)
|
| 88 |
output = gr.Textbox(label="")
|
| 89 |
-
choice.change(setup_summarization_llm, inputs=[choice,
|
| 90 |
with gr.Row():
|
| 91 |
choice = gr.Radio(label="Sentiment Analysis LLM", choices=sentiment_analysis_llm_choices)
|
| 92 |
output = gr.Textbox(label="")
|
| 93 |
-
choice.change(
|
| 94 |
with gr.Row():
|
| 95 |
choice = gr.Radio(label="Question/Answer LLM", choices=question_answer_llm_choices)
|
| 96 |
output = gr.Textbox(label="")
|
| 97 |
-
choice.change(
|
| 98 |
with gr.Group("Summarization Method"):
|
| 99 |
choice = gr.Radio(label="Summarization Method", choices=summarize_method_choices)
|
| 100 |
output = gr.Textbox(label="")
|
|
@@ -102,16 +104,16 @@ with gr.Blocks() as demo:
|
|
| 102 |
with gr.Group("Summarize Podcast"):
|
| 103 |
summary = gr.Textbox(label="Summary of Podcast")
|
| 104 |
submit_button = gr.Button("Generate Summary")
|
| 105 |
-
submit_button.click(summarize, inputs=[rtf_file, transcript_file_name, summarization_method,
|
| 106 |
with gr.Group("Aspects and Sentiment of Podcast"):
|
| 107 |
sentiment = gr.Textbox(label="Aspect Based Sentiments")
|
| 108 |
submit_button = gr.Button("Generate Aspects and Summary")
|
| 109 |
-
submit_button.click(generate_aspects_and_sentiments, inputs=[rtf_file, transcript_file_name,
|
| 110 |
with gr.Group("Question/Answer"):
|
| 111 |
gr.Markdown("Question/Answer")
|
| 112 |
question = gr.Textbox(label="Question")
|
| 113 |
answer = gr.Textbox(label="Answer")
|
| 114 |
answer_button = gr.Button("Answer Question")
|
| 115 |
-
answer_button.click(get_answer_for, inputs=[question, transcript_file_name,
|
| 116 |
|
| 117 |
demo.launch()
|
|
|
|
| 4 |
from tools.answer_bot import answer_question
|
| 5 |
from tools.aspect_and_sentiment_extraction import extract_aspects_and_sentiment
|
| 6 |
|
| 7 |
+
def get_answer_for(user_question, transcript_file_name, question_answer_llm_choice):
|
| 8 |
if transcript_file_name is None:
|
| 9 |
answer_text = "No Transcript Uploaded, Upload RTF File First", ""
|
| 10 |
+
elif not question_answer_llm_choice:
|
| 11 |
answer_text = "No LLM Selected, select one"
|
| 12 |
elif not user_question:
|
| 13 |
answer_text = "Question Not Given"
|
| 14 |
else:
|
| 15 |
# Answer the user's question using the question-answering model
|
| 16 |
+
answer_text = answer_question(question=user_question, transcript_file_name=transcript_file_name, llm_choice=question_answer_llm_choice)
|
| 17 |
|
| 18 |
return answer_text.lstrip(), transcript_file_name, llm_choice
|
| 19 |
|
| 20 |
+
def summarize(uploaded_file, transcript_file_name, summarization_method, summarization_llm_choice):
|
| 21 |
if transcript_file_name is None:
|
| 22 |
summary = "No Transcript Uploaded, Upload RTF File First", ""
|
| 23 |
+
elif not summarization_llm_choice:
|
| 24 |
summary = "No LLM Selected, select one"
|
| 25 |
elif not summarization_method:
|
| 26 |
summary = "No Summarization Method Selected , select one"
|
| 27 |
else:
|
| 28 |
# Summarize the content
|
| 29 |
+
summary = summarize_podcast(transcript_file_name=transcript_file_name, summarization_method=summarization_method, llm_choice=summarization_llm_choice).lstrip()
|
| 30 |
|
| 31 |
return summary, transcript_file_name, summarization_method, llm_choice
|
| 32 |
|
| 33 |
+
def generate_aspects_and_sentiments(uploaded_file, transcript_file_name, sentiment_analysis_llm_choice):
|
| 34 |
if transcript_file_name is None:
|
| 35 |
sentiment = "No Transcript Uploaded, Upload RTF File First", ""
|
| 36 |
+
elif not sentiment_analysis_llm_choice:
|
| 37 |
sentiment = "No LLM Selected, select one"
|
| 38 |
else:
|
| 39 |
# Aspect-Based Sentiment Analysis
|
| 40 |
+
sentiment = extract_aspects_and_sentiment(transcript_file_name=transcript_file_name, llm_choice=sentiment_analysis_llm_choice).lstrip()
|
| 41 |
|
| 42 |
+
return sentiment, transcript_file_name, sentiment_analysis_llm_choice
|
| 43 |
|
| 44 |
def setup_rtf_file_handle(uploaded_file, transcript_file_name):
|
| 45 |
if not uploaded_file:
|
|
|
|
| 49 |
status = "Upload Success"
|
| 50 |
return status, transcript_file_name
|
| 51 |
|
| 52 |
+
def setup_summarization_llm(choice, summarization_llm_choice):
|
| 53 |
set_summarization_llm(choice)
|
| 54 |
+
summarization_llm_choice = choice
|
| 55 |
+
return choice, summarization_llm_choice
|
| 56 |
|
| 57 |
+
def setup_sentiment_analysis_llm(choice, sentiment_analysis_llm_choice):
|
| 58 |
set_sentiment_analysis_llm(choice)
|
| 59 |
+
sentiment_analysis_llm_choice = choice
|
| 60 |
+
return choice, sentiment_analysis_llm_choice
|
| 61 |
|
| 62 |
+
def setup_question_answer_llm(choice, question_answer_llm_choice):
|
| 63 |
set_question_answer_llm(choice)
|
| 64 |
+
question_answer_llm_choice = choice
|
| 65 |
+
return choice, question_answer_llm_choice
|
| 66 |
|
| 67 |
def setup_summarization_method(choice, summarization_method):
|
| 68 |
summarization_method = choice
|
|
|
|
| 76 |
with gr.Blocks() as demo:
|
| 77 |
transcript_file_name = gr.State()
|
| 78 |
summarization_method = gr.State()
|
| 79 |
+
question_answer_llm_choice = gr.State()
|
| 80 |
+
sentiment_analysis_llm_choice = gr.State()
|
| 81 |
+
summarization_llm_choice = gr.State()
|
| 82 |
with gr.Group("Upload RTF File"):
|
| 83 |
rtf_file = gr.File(label="Podcast Transcript RTF file")
|
| 84 |
submit_button = gr.Button("Upload File")
|
|
|
|
| 88 |
with gr.Row():
|
| 89 |
choice = gr.Radio(label="Summarization LLM", choices=summarization_llm_choices)
|
| 90 |
output = gr.Textbox(label="")
|
| 91 |
+
choice.change(setup_summarization_llm, inputs=[choice,summarization_llm_choice], outputs=[output,summarization_llm_choice])
|
| 92 |
with gr.Row():
|
| 93 |
choice = gr.Radio(label="Sentiment Analysis LLM", choices=sentiment_analysis_llm_choices)
|
| 94 |
output = gr.Textbox(label="")
|
| 95 |
+
choice.change(setup_sentiment_analysis_llm, inputs=[choice,sentiment_analysis_llm_choice], outputs=[output,sentiment_analysis_llm_choice])
|
| 96 |
with gr.Row():
|
| 97 |
choice = gr.Radio(label="Question/Answer LLM", choices=question_answer_llm_choices)
|
| 98 |
output = gr.Textbox(label="")
|
| 99 |
+
choice.change(set_question_answer_llm, inputs=[choice,question_answer_llm_choice], outputs=[output,question_answer_llm_choice])
|
| 100 |
with gr.Group("Summarization Method"):
|
| 101 |
choice = gr.Radio(label="Summarization Method", choices=summarize_method_choices)
|
| 102 |
output = gr.Textbox(label="")
|
|
|
|
| 104 |
with gr.Group("Summarize Podcast"):
|
| 105 |
summary = gr.Textbox(label="Summary of Podcast")
|
| 106 |
submit_button = gr.Button("Generate Summary")
|
| 107 |
+
submit_button.click(summarize, inputs=[rtf_file, transcript_file_name, summarization_method, summarization_llm_choice], outputs=[summary, transcript_file_name, summarization_method, summarization_llm_choice])
|
| 108 |
with gr.Group("Aspects and Sentiment of Podcast"):
|
| 109 |
sentiment = gr.Textbox(label="Aspect Based Sentiments")
|
| 110 |
submit_button = gr.Button("Generate Aspects and Summary")
|
| 111 |
+
submit_button.click(generate_aspects_and_sentiments, inputs=[rtf_file, transcript_file_name, sentiment_analysis_llm_choice], outputs=[sentiment, transcript_file_name, sentiment_analysis_llm_choice])
|
| 112 |
with gr.Group("Question/Answer"):
|
| 113 |
gr.Markdown("Question/Answer")
|
| 114 |
question = gr.Textbox(label="Question")
|
| 115 |
answer = gr.Textbox(label="Answer")
|
| 116 |
answer_button = gr.Button("Answer Question")
|
| 117 |
+
answer_button.click(get_answer_for, inputs=[question, transcript_file_name, question_answer_llm_choice], outputs=[answer, transcript_file_name, question_answer_llm_choice])
|
| 118 |
|
| 119 |
demo.launch()
|
helpers/model_utils.py
CHANGED
|
@@ -20,7 +20,7 @@ def _set_llm_based_on_choice(choice):
|
|
| 20 |
model_name = "gpt-4o"
|
| 21 |
llm = OpenAI(model=model_name, temperature=0, api_key=openai_api_key)
|
| 22 |
elif choice == ANTHROPIC:
|
| 23 |
-
model_name = "
|
| 24 |
llm = ChatAnthropic(model_name=model_name, anthropic_api_key=anthropic_api_key)
|
| 25 |
elif choice == LLAMA3:
|
| 26 |
model_name = "llama3"
|
|
|
|
| 20 |
model_name = "gpt-4o"
|
| 21 |
llm = OpenAI(model=model_name, temperature=0, api_key=openai_api_key)
|
| 22 |
elif choice == ANTHROPIC:
|
| 23 |
+
model_name = "claude-2.1"
|
| 24 |
llm = ChatAnthropic(model_name=model_name, anthropic_api_key=anthropic_api_key)
|
| 25 |
elif choice == LLAMA3:
|
| 26 |
model_name = "llama3"
|