indiapuig commited on
Commit
63120d8
·
verified ·
1 Parent(s): e8acf8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -6
app.py CHANGED
@@ -1,26 +1,60 @@
1
  import gradio as gr
2
- # import random
3
  from huggingface_hub import InferenceClient
4
 
5
  client = InferenceClient("microsoft/phi-4")
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def respond(message, history):
8
- messages = [{"role": "system", "content": "You are a friendly, helpful but professional personal tutor for 14 to 16 year old students who are aiming to complete their GCSEs within the next two years. Primarily your expertise lies within the three sciences: Biology, Physics and Chemistry but for now you will focus on providing the students GCSE knowledge for Biology at a Foundation and Higher Level according to the government and exam board requirements - mainly focusing on AQA. The student will indicate whether they are operating at a Higher or Foundation level of knowledge. Through interacting with the user, you will aim to educate the user on different topics within Biology through detailed but concise explanations and interactive games and quizzes to develop their knowledge. The process you will take is review the knowledge in small sections according to the specification, ask the user if they have any more questions, ask 1 by 1 exam-style questions to the user and once they have entered in their response then mark the question the user has answered to provide feedback on any errors they have made and what they could do to improve their response to achieve full marks. This process is circular so the user will keep reviewing different topics until they indicate to you that they are done with their study session or there is an extended period of inactivity."}]
 
 
 
 
 
 
 
9
 
10
  if history:
11
  messages.extend(history)
12
 
13
  messages.append({"role": "user", "content": message})
14
 
15
-
16
  response = client.chat_completion(
17
  messages,
18
  max_tokens=300
19
  )
20
  return response['choices'][0]['message']['content'].strip()
21
 
22
- print("Hello world")
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- chatbot = gr.ChatInterface(respond, type="messages", title="ACE it!")
25
- chatbot.launch()
26
 
 
1
  import gradio as gr
 
2
  from huggingface_hub import InferenceClient
3
 
4
  client = InferenceClient("microsoft/phi-4")
5
 
6
+ # Topics
7
+ BIO_TOPICS = [
8
+ "Cell Biology",
9
+ "Organisation",
10
+ "Infection and Response",
11
+ "Bioenergetics",
12
+ "Homeostasis and Response",
13
+ "Inheritance, Variation and Evolution",
14
+ "Ecology"
15
+ ]
16
+
17
+ chosen_topic = None
18
+
19
+ def set_topic(topic):
20
+ global chosen_topic
21
+ chosen_topic = topic
22
+ return f"✅ Great! You've chosen **{topic}**. Let's start your study session."
23
+
24
  def respond(message, history):
25
+ global chosen_topic
26
+ if not chosen_topic:
27
+ return "⚠️ Please choose a topic before starting."
28
+
29
+ messages = [{
30
+ "role": "system",
31
+ "content": f"You are a friendly GCSE Biology tutor focusing on **{chosen_topic}**."
32
+ }]
33
 
34
  if history:
35
  messages.extend(history)
36
 
37
  messages.append({"role": "user", "content": message})
38
 
 
39
  response = client.chat_completion(
40
  messages,
41
  max_tokens=300
42
  )
43
  return response['choices'][0]['message']['content'].strip()
44
 
45
+ # Create the Gradio interface
46
+ with gr.Blocks() as demo:
47
+ gr.Markdown("# ACE it! 📚 — GCSE Biology Tutor")
48
+
49
+ with gr.Row():
50
+ topic_dropdown = gr.Dropdown(choices=BIO_TOPICS, label="Choose a Biology Topic")
51
+ topic_button = gr.Button("Confirm Topic")
52
+
53
+ topic_output = gr.Markdown()
54
+
55
+ chatbot = gr.ChatInterface(respond, type="messages", title="ACE it!")
56
+
57
+ topic_button.click(set_topic, inputs=topic_dropdown, outputs=topic_output)
58
 
59
+ demo.launch()
 
60