File size: 923 Bytes
dece718
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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}")