AnishaG0201 commited on
Commit
fdb52c6
1 Parent(s): f172940

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -77
app.py CHANGED
@@ -1,63 +1,9 @@
1
  import streamlit as st
2
- # from function import GetLLMResponse
3
 
4
  from langchain_community.llms import OpenAI
5
  from langchain_google_genai import ChatGoogleGenerativeAI
6
 
7
- def get_answers(questions,model):
8
- st.write("running get answers function answering following questions",questions)
9
-
10
-
11
- answer_prompt = (f"Answer the following questions {questions}")
12
-
13
-
14
- if model == "Open AI":
15
- llm = OpenAI(temperature=0.7, openai_api_key=st.secrets["OPENAI_API_KEY"])
16
- answers = llm(answer_prompt)
17
- # return questions
18
-
19
- elif model == "Gemini":
20
- llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
21
- answers = llm.invoke(answer_prompt)
22
- answers = answers.content
23
- # return questions.content
24
-
25
- return(answers)
26
-
27
-
28
-
29
-
30
- def GetLLMResponse(selected_topic_level, selected_topic,num_quizzes, model):
31
-
32
-
33
-
34
- st.write("Selected option:", selected_topic_level,selected_topic,num_quizzes)
35
-
36
-
37
-
38
- question_prompt = (f'I want you to just generate question with this specification: Generate a {selected_topic_level} math quiz on the topic of {selected_topic}. Generate only {num_quizzes} questions not more and without providing answers.')
39
-
40
- st.write("running get llm response and print question prompt",question_prompt)
41
- if model == "Open AI":
42
- llm = OpenAI(temperature=0.7, openai_api_key=st.secrets["OPENAI_API_KEY"])
43
- questions = llm(question_prompt)
44
-
45
-
46
- elif model == "Gemini":
47
- llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
48
- questions = llm.invoke(question_prompt)
49
- questions = questions.content
50
- # return questions.content
51
-
52
-
53
- st.write("print questions",questions)
54
- answers = get_answers(questions,model)
55
-
56
- # st.write(questions,answers)
57
- return(questions,answers)
58
-
59
-
60
-
61
 
62
  # Page configuration
63
  st.set_page_config(page_title="Generate Math Quizzes",
@@ -105,31 +51,31 @@ def main():
105
  if submit:
106
  questions,answers = GetLLMResponse(selected_topic_level, selected_topic, num_quizzes, model)
107
  st.write("printing the response",questions,answers)
108
- # with st.spinner("Generating Quizzes..."):
109
- # questions,answers = GetLLMResponse(selected_topic_level, selected_topic, num_quizzes, model)
110
- # st.success("Quizzes Generated!")
111
-
112
-
113
- # st.write("printing the response",questions,answers)
114
- # # # Display questions and answers in a table
115
- # # if response:
116
- # # st.subheader("Quiz Questions and Answers:")
117
- # # # Prepare data for the table
118
- # # # col1, col2 = st.columns(2)
119
- # # # with col1:
120
- # # # st.subheader("Questions")
121
- # # # questions = response
122
- # # # st.write(questions)
123
 
124
- # # # with col2:
125
- # # # st.subheader("Answers")
126
- # # # answers = response
127
- # # # st.write(answers)
128
 
129
- # # st.write("printing the response",questions,answers)
130
 
131
- # # else:
132
- # # st.warning("No Quiz Questions and Answers")
133
 
134
  else:
135
  st.warning("Click the 'Generate Quizzes' button to create quizzes.")
 
1
  import streamlit as st
2
+ from function import GetLLMResponse
3
 
4
  from langchain_community.llms import OpenAI
5
  from langchain_google_genai import ChatGoogleGenerativeAI
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Page configuration
9
  st.set_page_config(page_title="Generate Math Quizzes",
 
51
  if submit:
52
  questions,answers = GetLLMResponse(selected_topic_level, selected_topic, num_quizzes, model)
53
  st.write("printing the response",questions,answers)
54
+ with st.spinner("Generating Quizzes..."):
55
+ questions,answers = GetLLMResponse(selected_topic_level, selected_topic, num_quizzes, model)
56
+ st.success("Quizzes Generated!")
57
+
58
+
59
+
60
+ # Display questions and answers in a table
61
+ if response:
62
+ st.subheader("Quiz Questions and Answers:")
63
+ # Prepare data for the table
64
+ # col1, col2 = st.columns(2)
65
+ # with col1:
66
+ # st.subheader("Questions")
67
+ # questions = response
68
+ # st.write(questions)
69
 
70
+ # with col2:
71
+ # st.subheader("Answers")
72
+ # answers = response
73
+ # st.write(answers)
74
 
75
+ st.write("printing the response",questions,answers)
76
 
77
+ else:
78
+ st.warning("No Quiz Questions and Answers")
79
 
80
  else:
81
  st.warning("Click the 'Generate Quizzes' button to create quizzes.")