Chad commited on
Commit ·
ab92035
1
Parent(s): 46568b4
45672uwwewewewedwd
Browse files
app.py
CHANGED
|
@@ -44,6 +44,26 @@ def generate_reply(user_input, chat_history):
|
|
| 44 |
chat_history.append({"role": "assistant", "content": reply})
|
| 45 |
return chat_history, chat_history, ""
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
def toggle_language(language):
|
| 48 |
"""Toggle UI elements between English and French."""
|
| 49 |
if language == "english":
|
|
@@ -83,6 +103,11 @@ with gr.Blocks() as interface:
|
|
| 83 |
send_button = gr.Button("Send")
|
| 84 |
reset_button = gr.Button("New Conversation")
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
state = gr.State([])
|
| 87 |
|
| 88 |
examples = gr.Examples(
|
|
@@ -108,5 +133,11 @@ with gr.Blocks() as interface:
|
|
| 108 |
|
| 109 |
reset_button.click(lambda: (gr.update(value=[]), []), outputs=[chatbot, state])
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
if __name__ == "__main__":
|
| 112 |
interface.launch(share=True)
|
|
|
|
| 44 |
chat_history.append({"role": "assistant", "content": reply})
|
| 45 |
return chat_history, chat_history, ""
|
| 46 |
|
| 47 |
+
def generate_quiz(subject, num_questions):
|
| 48 |
+
quiz_questions = []
|
| 49 |
+
try:
|
| 50 |
+
for i in range(num_questions):
|
| 51 |
+
prompt = f"Generate a multiple-choice history question about {subject}. Include four options and specify the correct answer."
|
| 52 |
+
response = client.chat.completions.create(
|
| 53 |
+
model="llama3-70b-8192",
|
| 54 |
+
messages=[{"role": "user", "content": prompt}],
|
| 55 |
+
temperature=0.7,
|
| 56 |
+
max_completion_tokens=256,
|
| 57 |
+
top_p=0.95,
|
| 58 |
+
stream=False,
|
| 59 |
+
stop=None,
|
| 60 |
+
)
|
| 61 |
+
question = response.choices[0].message.content or "Error generating question."
|
| 62 |
+
quiz_questions.append(question)
|
| 63 |
+
except Exception as error:
|
| 64 |
+
quiz_questions.append(f"Error: {error}")
|
| 65 |
+
return "\n\n".join(quiz_questions)
|
| 66 |
+
|
| 67 |
def toggle_language(language):
|
| 68 |
"""Toggle UI elements between English and French."""
|
| 69 |
if language == "english":
|
|
|
|
| 103 |
send_button = gr.Button("Send")
|
| 104 |
reset_button = gr.Button("New Conversation")
|
| 105 |
|
| 106 |
+
quiz_subject = gr.Textbox(label="Quiz Subject")
|
| 107 |
+
quiz_num_questions = gr.Number(label="Number of Questions", value=5, precision=0)
|
| 108 |
+
quiz_button = gr.Button("Start Quiz")
|
| 109 |
+
quiz_output = gr.Textbox(label="Quiz Questions", interactive=False)
|
| 110 |
+
|
| 111 |
state = gr.State([])
|
| 112 |
|
| 113 |
examples = gr.Examples(
|
|
|
|
| 133 |
|
| 134 |
reset_button.click(lambda: (gr.update(value=[]), []), outputs=[chatbot, state])
|
| 135 |
|
| 136 |
+
quiz_button.click(
|
| 137 |
+
fn=generate_quiz,
|
| 138 |
+
inputs=[quiz_subject, quiz_num_questions],
|
| 139 |
+
outputs=[quiz_output]
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
if __name__ == "__main__":
|
| 143 |
interface.launch(share=True)
|