Spaces:
Runtime error
Runtime error
| import os | |
| # Set up OpenAI API credentials | |
| import openai | |
| openai.api_key = os.getenv('api_token') | |
| 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(aiquotient,response): | |
| prompt_sum = f""" | |
| Generate a question that evaluates the understanding of AI concepts of a person. Ensure that the question challenges the {aiquotient} of the person and is connected to the response {response}. Limit it to at the max 20 words. Here are some examples: | |
| What is reinforcement learning? How is it different from supervised and unsupervised learning? | |
| What is the difference between a model and an algorithm? | |
| Explain the concept of "overfitting" in machine learning and its potential impact on model performance. | |
| Explain how natural language processing (NLP) is employed in virtual assistants like Siri or Alexa. | |
| Explain how Uber uses Machine Learning with an example | |
| How does ChatGPT work? | |
| Describe the ethical implications of using AI in autonomous vehicles and potential biases in facial recognition systems. | |
| What is Bias-Variance tradeoff? | |
| What is the importance of p-value? | |
| What are the assumptions under which Linear Regression works? | |
| What are the limitations of K-Nearest Neighbors algorithm? | |
| """ | |
| response_sum = choose_topic(prompt_sum) | |
| return response_sum | |
| def evaluate(response): | |
| prompt_sum = f""" | |
| Imagine you are Alan Turing, the scientist who devised Turing test. Analyze the user's response {response} and figure out the question. Then identify areas of improvement, provide the ideal answer and calculate AI Quotient. | |
| Your response should be: | |
| [AI Quotient, Areas of Improvement, Ideal Answer] | |
| """ | |
| response_sum = get_completion(prompt_sum) | |
| return response_sum | |
| import gradio as gr | |
| def transcribe(audio): | |
| print(audio) | |
| # Whisper API | |
| audio_file = open(audio, "rb") | |
| transcript = openai.Audio.transcribe("whisper-1", audio_file) | |
| print(transcript) | |
| eval = evaluate(transcript) | |
| return eval | |
| question = generate_topic(aiquotient=100,response='I am an expert in Machine Learning. Ask me a difficult question') | |
| inputs = gr.Audio(source="microphone", type="filepath",label=question) | |
| bot = gr.Interface(fn=transcribe, inputs=inputs, outputs="text", title="Ask Turing: Improve your AI Quotient", | |
| description="Answer the question and receive feedback") | |
| bot.launch() |