Tutor / app.py
iqra785's picture
Create app.py
dece718 verified
raw
history blame contribute delete
923 Bytes
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
# Load a pre-trained model and tokenizer
model_name = "t5-small" # You can experiment with larger models like "t5-base" or "t5-large"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
# Create a pipeline for question-answering
tutor_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
# Function to interact with the Tutor AI
def tutor_ai(question):
input_text = f"explain: {question}"
response = tutor_pipeline(input_text, max_length=200, num_return_sequences=1)
return response[0]['generated_text']
# Example usage
question = "What is the Pythagorean theorem?"
answer = tutor_ai(question)
print(f"Q: {question}\nA: {answer}")
question = "How do you solve a quadratic equation?"
answer = tutor_ai(question)
print(f"Q: {question}\nA: {answer}")