File size: 2,209 Bytes
6554411
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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()