Spaces:
Runtime error
Runtime error
Commit ·
89d3fbe
1
Parent(s): b4ebb3b
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
# Set up OpenAI API credentials
|
| 3 |
+
import openai
|
| 4 |
+
openai.api_key = "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"
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
def get_completion(prompt, model="gpt-3.5-turbo"):
|
| 8 |
+
messages = [{"role": "user", "content": prompt}]
|
| 9 |
+
response = openai.ChatCompletion.create(
|
| 10 |
+
model=model,
|
| 11 |
+
messages=messages,
|
| 12 |
+
temperature=0, # this is the degree of randomness of the model's output
|
| 13 |
+
)
|
| 14 |
+
return response.choices[0].message["content"]
|
| 15 |
+
|
| 16 |
+
def choose_topic(prompt, model="gpt-3.5-turbo"):
|
| 17 |
+
messages = [{"role": "user", "content": prompt}]
|
| 18 |
+
response = openai.ChatCompletion.create(
|
| 19 |
+
model=model,
|
| 20 |
+
messages=messages,
|
| 21 |
+
temperature=0.9, # this is the degree of randomness of the model's output
|
| 22 |
+
)
|
| 23 |
+
return response.choices[0].message["content"]
|
| 24 |
+
|
| 25 |
+
def generate_topic(aiquotient,response):
|
| 26 |
+
prompt_sum = f"""
|
| 27 |
+
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:
|
| 28 |
+
What is reinforcement learning? How is it different from supervised and unsupervised learning?
|
| 29 |
+
What is the difference between a model and an algorithm?
|
| 30 |
+
Explain the concept of "overfitting" in machine learning and its potential impact on model performance.
|
| 31 |
+
Explain how natural language processing (NLP) is employed in virtual assistants like Siri or Alexa.
|
| 32 |
+
Explain how Uber uses Machine Learning with an example
|
| 33 |
+
How does ChatGPT work?
|
| 34 |
+
Describe the ethical implications of using AI in autonomous vehicles and potential biases in facial recognition systems.
|
| 35 |
+
What is Bias-Variance tradeoff?
|
| 36 |
+
What is the importance of p-value?
|
| 37 |
+
What are the assumptions under which Linear Regression works?
|
| 38 |
+
What are the limitations of K-Nearest Neighbors algorithm?
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
response_sum = choose_topic(prompt_sum)
|
| 42 |
+
return response_sum
|
| 43 |
+
|
| 44 |
+
def evaluate(response):
|
| 45 |
+
prompt_sum = f"""
|
| 46 |
+
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.
|
| 47 |
+
Your response should be:
|
| 48 |
+
[AI Quotient, Areas of Improvement, Ideal Answer]
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
response_sum = get_completion(prompt_sum)
|
| 52 |
+
return response_sum
|
| 53 |
+
|
| 54 |
+
import gradio as gr
|
| 55 |
+
def transcribe(audio):
|
| 56 |
+
print(audio)
|
| 57 |
+
|
| 58 |
+
# Whisper API
|
| 59 |
+
|
| 60 |
+
audio_file = open(audio, "rb")
|
| 61 |
+
transcript = openai.Audio.transcribe("whisper-1", audio_file)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
print(transcript)
|
| 65 |
+
eval = evaluate(transcript)
|
| 66 |
+
|
| 67 |
+
return eval
|
| 68 |
+
|
| 69 |
+
question = generate_topic(aiquotient=100,response='I am an expert in Machine Learning. Ask me a difficult question')
|
| 70 |
+
|
| 71 |
+
inputs = gr.Audio(source="microphone", type="filepath",label=question)
|
| 72 |
+
|
| 73 |
+
bot = gr.Interface(fn=transcribe, inputs=inputs, outputs="text", title="Ask Turing: Improve your AI Quotient",
|
| 74 |
+
description="This is a gradio app",
|
| 75 |
+
article="Visit aiquotient.app for more details")
|
| 76 |
+
|
| 77 |
+
bot.launch()
|