johnpaulbin commited on
Commit
1e63407
1 Parent(s): cc545c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py CHANGED
@@ -104,6 +104,45 @@ def update_question(mock_index, score, incorrect_questions):
104
  question, ans1, ans2, ans3, ans4, correct = display_mock_question(mock_index, score, incorrect_questions)
105
  return gr.update(value=question), gr.update(value=ans1, visible=True), gr.update(value=ans2, visible=True), gr.update(value=ans3, visible=True), gr.update(value=ans4, visible=True)
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  # Gradio interface
108
  with gr.Blocks() as demo:
109
  available_weeks = get_available_weeks()
@@ -126,6 +165,13 @@ with gr.Blocks() as demo:
126
  prev_btn = gr.Button("Previous")
127
  reveal_btn = gr.Button("Reveal Answer")
128
  next_btn = gr.Button("Next")
 
 
 
 
 
 
 
129
 
130
  # Start button action to reveal the flashcard section
131
  start_button.click(lambda: gr.update(visible=True), inputs=[], outputs=flashcard_section)
 
104
  question, ans1, ans2, ans3, ans4, correct = display_mock_question(mock_index, score, incorrect_questions)
105
  return gr.update(value=question), gr.update(value=ans1, visible=True), gr.update(value=ans2, visible=True), gr.update(value=ans3, visible=True), gr.update(value=ans4, visible=True)
106
 
107
+ with open("aa2.txt", "r") as f:
108
+ prompt = f.read()
109
+
110
+ genai.configure(api_key=os.environ["GEMINI_API_KEY"])
111
+
112
+ # Create the model configuration
113
+ generation_config = {
114
+ "temperature": 0.5,
115
+ "top_p": 0.98,
116
+ "top_k": 64,
117
+ "max_output_tokens": 8192,
118
+ "response_mime_type": "text/plain",
119
+ }
120
+
121
+ model = genai.GenerativeModel(
122
+ model_name="gemini-1.5-flash-8b-exp-0827",
123
+ generation_config=generation_config,
124
+ )
125
+
126
+ # AI Chatbot function
127
+ def chat_with_ai(user_input):
128
+ chat_session = model.start_chat(
129
+ history=[
130
+ {
131
+ "role": "user",
132
+ "parts": [ prompt ],
133
+ },
134
+ {
135
+ "role": "model",
136
+ "parts": [
137
+ "Sure, I can answer your question. \n",
138
+ ],
139
+ },
140
+ ]
141
+ )
142
+
143
+ response = chat_session.send_message(user_input)
144
+ return response.text
145
+
146
  # Gradio interface
147
  with gr.Blocks() as demo:
148
  available_weeks = get_available_weeks()
 
165
  prev_btn = gr.Button("Previous")
166
  reveal_btn = gr.Button("Reveal Answer")
167
  next_btn = gr.Button("Next")
168
+
169
+ with gr.Column(visible=True):
170
+ chat_input = gr.Textbox(label="Ask a question to the A.I.")
171
+ with gr.Row():
172
+ gr.Markdown(">Note: This A.I. has only been given the NBAA Management guide. Use the flashcards for specific week information.")
173
+ chat_output = gr.Markdown(label="AI Response")
174
+ chat_button = gr.Button("Ask AI")
175
 
176
  # Start button action to reveal the flashcard section
177
  start_button.click(lambda: gr.update(visible=True), inputs=[], outputs=flashcard_section)