DataWizard9742 commited on
Commit
6554411
·
1 Parent(s): c4056ff

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+
4
+ openai.api_key = "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"
5
+
6
+ tutoring_prompt = "Q: You are asked to give an brief description of the topic in accordance with the age mentioned"
7
+
8
+ # Function to generate a response from the virtual tutor
9
+ def get_tutor_response(question, age):
10
+ prompt = tutoring_prompt + question + "\nAge: " + str(age) + "\nA:"
11
+ response = openai.Completion.create(
12
+ engine="text-davinci-003",
13
+ prompt=prompt,
14
+ max_tokens=500, # Adjust the response length as needed
15
+ temperature=0.7,
16
+ n=1,
17
+ stop=None,
18
+ )
19
+
20
+ # Extract the generated answer from the response
21
+ answer = response.choices[0].text.strip()
22
+ return answer
23
+
24
+ # Function to generate assignment questions
25
+ def generate_assignment_questions(content):
26
+ # Generate assignment questions using ChatGPT
27
+ response = openai.Completion.create(
28
+ engine="text-davinci-003",
29
+ prompt=content + "\nQ:",
30
+ max_tokens=500, # Adjust the response length as needed
31
+ temperature=0.7,
32
+ n=5, # Adjust the number of questions generated
33
+ stop=None,
34
+ )
35
+
36
+ # Extract the generated questions from the response
37
+ questions = [choice.text.strip() for choice in response.choices]
38
+
39
+ return questions
40
+
41
+ # Streamlit app
42
+ def main():
43
+ # Set the title and description of the app
44
+ st.title("Virtual Tutoring Assistant")
45
+ st.write("Ask a question, and the virtual tutor will provide an answer.")
46
+
47
+ # Get user's question
48
+ user_question = st.text_input("Ask a question:")
49
+
50
+ # Get the student's age
51
+ student_age = st.slider("Student's Age:", min_value=6, max_value=40, value=12)
52
+
53
+ if user_question:
54
+ # Generate response from the virtual tutor
55
+ tutor_answer = get_tutor_response(user_question, student_age)
56
+ st.write("Tutor:", tutor_answer)
57
+
58
+ # Generate assignment questions based on the tutor's response
59
+ assignment_questions = generate_assignment_questions(tutor_answer)
60
+ st.write("Assignment Questions:")
61
+ for i, question in enumerate(assignment_questions):
62
+ st.write(f"{i+1}. {question}")
63
+
64
+ if __name__ == "__main__":
65
+ main()