Spaces:
Sleeping
Sleeping
File size: 8,642 Bytes
0ba8f51 d67b956 d946d46 58e52a1 0ba8f51 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | import openai
import os
os.environ["OPENAI_API_KEY"] = os.getenv('open_ai')
openai.api_key = os.getenv('open_ai')
import gradio as gr
def get_completion(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0, # this is the degree of randomness of the model's output
)
return response.choices[0].message["content"]
def choose_topic(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0.9, # this is the degree of randomness of the model's output
)
return response.choices[0].message["content"]
def generate_topic():
prompt_sum = f"""
Imagine you are a public speaking enthusiast. Generate a table topic that tests the impromptu speaking skills of a person. Here are some examples:
Life As an Object
Walking Dictionary
Color your world
A second chance
The day I met Elvis
Did you know that I once...?
Home is where the heart is
What doesn't kill you makes you ......
Keep your friends close. And your enemies closer.
"""
response_sum = choose_topic(prompt_sum)
return response_sum
def audio_summary(transcript,topic):
prompt_sum = f"""
As Cicero, the master orator, you are tasked with evaluating the effectiveness of a persuasive speech based on his renowned "five canons of rhetoric." These canons serve as a framework for analyzing and crafting persuasive speeches and arguments. Your evaluation will focus on the following aspects:
1. Invention (Quality of Arguments and Evidence):
Assess the logical and compelling nature of the arguments presented by the speaker for the topic: {topic}
Examine the evidence provided to support the speaker's points and evaluate its credibility.
2. Arrangement (Organization and Structure):
Analyze the logical flow of the speaker's ideas and the overall structure of the argument.
Evaluate whether the arrangement of points enhances the coherence and clarity of the speech.
3. Style (Word Choice, Sentence Structure, Rhetorical Devices):
Assess the appropriateness and effectiveness of the speaker's word choice and sentence structure.
Evaluate the use of rhetorical devices to enhance the persuasiveness of the speech.
4. Memory (Use of Examples, Comparisons, Narratives):
Examine the speaker's use of examples, comparisons, and narratives to illustrate their points.
Evaluate how effectively the speaker makes their arguments memorable through storytelling.
5. Delivery (Voice, Gestures, Eye Contact, Presentation):
Assess the speaker's delivery style, including voice modulation.
Evaluate how well the delivery complements and enhances the content of the argument.
Prompt:
Imagine you are Cicero, the master orator. Your task is to evaluate the persuasive speech presented below based on your renowned "five canons of rhetoric." Provide a comprehensive evaluation report for the speaker, considering each canon's key attributes.
Speech Transcript:
{transcript}
Evaluation Report Format:
Invention:
Evaluate the quality of arguments and evidence.
Provide feedback on the logical strength of the points presented.
Arrangement:
Analyze the organization and structure of the speech.
Assess how well the logical flow enhances the speech's coherence.
Style:
Evaluate the word choice, sentence structure, and use of rhetorical devices.
Comment on the effectiveness of the speaker's stylistic choices.
Memory:
Examine the use of examples, comparisons, and narratives in the speech.
Assess how memorable the speaker's arguments are due to storytelling.
Overall Summary of Evaluation:
Provide a concise overview of the speech's strengths and areas for improvement.
Score on a Scale of 1-10:
Assign a rating to the speech's persuasiveness, considering all five canons consistently.
Use Cicero's comprehensive framework to deliver a thoughtful evaluation that highlights the speaker's strengths while providing constructive feedback for improvement.
"""
response_sum = get_completion(prompt_sum)
return response_sum
def improved_speech(topic,transcript,feedback):
prompt_sum = f'''
# Speech Improvement Assistant
## Overview
- The Assistant is tasked with improving a given speech based on provided feedback.
- The Assistant uses the provided feedback and the original speech transcript to create a revised version of the speech on the given topic.
## Tasks
- The Assistant must apply the feedback to the speech transcript.
- The Assistant must regenerate an improved version of the speech for the given topic.
## Parameters
- The {feedback} is the input provided to improve the speech.
- The {transcript} is the original speech text that requires improvement.
- The {topic} is the subject matter of the speech.
## Output
- The output of the Assistant will be an improved version of the speech.
- The improved speech should reflect the changes suggested in the feedback and still stay relevant to the given topic.
## Response Formatting
- The Assistant's responses should be formatted using Markdown.
- The Assistant's responses should be structured as a speech, with clear and concise sentences.
- The Assistant's responses should maintain the tone and style appropriate for the topic of the speech.'''
response_sum = get_completion(prompt_sum)
return response_sum
def evaluator(transcript):
prompt_sum = f'''# Speech Analysis Assistant
## Assistant
- The Assistant is a speech analysis tool designed to evaluate and provide insights into a given speech.
- Assistant's main task is to analyze the speech and provide a detailed analysis of the grammar, diction, and the usage of filler words.
## Task
- The Assistant must identify and count the number of times filler words are used in the speech: {transcript}.
- The Assistant must analyze the grammar and diction of the speech.
- Based on the analysis, the Assistant should provide one single improvement tip.
## Parameters
- The Assistant is only to analyze the provided speech and should not make assumptions or use information from outside the speech.
## Output
- The Assistant's analysis should be thorough and detailed, highlighting the grammar, diction, and filler words usage of the speech.
- The Assistant's single improvement tip should be specific and actionable, based on the observations from the analysis.
## Response Formatting
- The Assistant's response should be formatted in markdown for easy readability.
- The Assistant should start with an H2 title, then describe the analysis of the grammar, diction, and filler words usage in separate sections.
- The Assistant should end the response with an H2 title 'Improvement Tip', followed by the suggested speech improvement tip.
'''
response_sum = get_completion(prompt_sum)
return response_sum
def transcribe(audio,topic):
print(audio)
output = ''' '''
# Whisper API
audio_file = open(audio, "rb")
transcript = openai.Audio.transcribe("whisper-1", audio_file)
output += f'''Here is your transcript: \n \n'''
yield output
output += transcript['text'] + '\n \n'
yield output
print(transcript)
output += f'''Overall Evaluation Report by Cicero: \n \n'''
yield output
eval = audio_summary(transcript,topic)
output += eval + '\n \n'
yield output
grammar_output = evaluator(transcript)
output += f'''Speech style improvements by Demosthenes: \n \n'''
yield output
output += grammar_output + '\n \n'
yield output
improv_speech = improved_speech(topic,transcript,eval)
output += f'''Improved version of the Speech by Aristotle: \n \n'''
yield output
output += improv_speech
yield output
return eval
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("# Table Topics Master: Improve Impromptu speaking skills 🎙️🔥")
btn_caption = gr.Button("Generate a topic")
caption = gr.Textbox(label="Here is your topic: ")
btn_caption.click(fn=generate_topic, outputs=caption)
audio_input = [gr.Audio(source="microphone", type="filepath", label="Start speaking"),caption]
btn_submit = gr.Button("Submit your response")
image_output = gr.Textbox(label="Your evaluation report would show up here")
btn_submit.click(fn=transcribe, inputs=audio_input, outputs=[image_output])
gr.close_all()
#demo.launch(share=True, debug=True)
# Launch the Gradio app
if __name__ == "__main__":
demo.queue(concurrency_count=5, max_size=20).launch() |