import streamlit as st import openai openai.api_key = "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" tutoring_prompt = "Q: You are asked to give an brief description of the topic in accordance with the age mentioned" # Function to generate a response from the virtual tutor def get_tutor_response(question, age): prompt = tutoring_prompt + question + "\nAge: " + str(age) + "\nA:" response = openai.Completion.create( engine="text-davinci-003", prompt=prompt, max_tokens=500, # Adjust the response length as needed temperature=0.7, n=1, stop=None, ) # Extract the generated answer from the response answer = response.choices[0].text.strip() return answer # Function to generate assignment questions def generate_assignment_questions(content): # Generate assignment questions using ChatGPT response = openai.Completion.create( engine="text-davinci-003", prompt=content + "\nQ:", max_tokens=500, # Adjust the response length as needed temperature=0.7, n=5, # Adjust the number of questions generated stop=None, ) # Extract the generated questions from the response questions = [choice.text.strip() for choice in response.choices] return questions # Streamlit app def main(): # Set the title and description of the app st.title("Virtual Tutoring Assistant") st.write("Ask a question, and the virtual tutor will provide an answer.") # Get user's question user_question = st.text_input("Ask a question:") # Get the student's age student_age = st.slider("Student's Age:", min_value=6, max_value=40, value=12) if user_question: # Generate response from the virtual tutor tutor_answer = get_tutor_response(user_question, student_age) st.write("Tutor:", tutor_answer) # Generate assignment questions based on the tutor's response assignment_questions = generate_assignment_questions(tutor_answer) st.write("Assignment Questions:") for i, question in enumerate(assignment_questions): st.write(f"{i+1}. {question}") if __name__ == "__main__": main()