iqra785 commited on
Commit
dece718
·
verified ·
1 Parent(s): 842182b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
2
+
3
+ # Load a pre-trained model and tokenizer
4
+ model_name = "t5-small" # You can experiment with larger models like "t5-base" or "t5-large"
5
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
6
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
7
+
8
+ # Create a pipeline for question-answering
9
+ tutor_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
10
+
11
+ # Function to interact with the Tutor AI
12
+ def tutor_ai(question):
13
+ input_text = f"explain: {question}"
14
+ response = tutor_pipeline(input_text, max_length=200, num_return_sequences=1)
15
+ return response[0]['generated_text']
16
+
17
+ # Example usage
18
+ question = "What is the Pythagorean theorem?"
19
+ answer = tutor_ai(question)
20
+ print(f"Q: {question}\nA: {answer}")
21
+
22
+ question = "How do you solve a quadratic equation?"
23
+ answer = tutor_ai(question)
24
+ print(f"Q: {question}\nA: {answer}")