pandion commited on
Commit
a2c1bc1
·
verified ·
1 Parent(s): e100819

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -1,6 +1,19 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def respond(
6
  message,
@@ -12,42 +25,42 @@ def respond(
12
  hf_token: gr.OAuthToken,
13
  ):
14
  """
15
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
 
16
  """
17
  client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
18
 
19
  messages = [{"role": "system", "content": system_message}]
20
-
21
  messages.extend(history)
22
-
23
  messages.append({"role": "user", "content": message})
24
 
25
  response = ""
26
-
27
- for message in client.chat_completion(
28
  messages,
29
  max_tokens=max_tokens,
30
  stream=True,
31
  temperature=temperature,
32
  top_p=top_p,
33
  ):
34
- choices = message.choices
35
  token = ""
36
  if len(choices) and choices[0].delta.content:
37
  token = choices[0].delta.content
38
-
39
  response += token
40
  yield response
41
 
42
 
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
  chatbot = gr.ChatInterface(
47
  respond,
48
  type="messages",
49
  additional_inputs=[
50
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
 
 
 
 
 
51
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
52
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
53
  gr.Slider(
@@ -65,6 +78,5 @@ with gr.Blocks() as demo:
65
  gr.LoginButton()
66
  chatbot.render()
67
 
68
-
69
  if __name__ == "__main__":
70
  demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ SYSTEM_PROMPT = (
5
+ "You are “Maya,” owner of Klinik Sehat Sentosa, a small outpatient clinic in Manado. "
6
+ "A student analyst will interview you to gather information requirements for a simple appointment & "
7
+ "queueing system (web + mobile).\n\n"
8
+ "Goals: reduce patient wait time, prevent double bookings, support WhatsApp reminders, basic daily reports.\n"
9
+ "Persona: friendly, busy, non-technical. Answer concretely from real operations. If the student is vague, "
10
+ "ask clarifying questions.\n"
11
+ "Scope boundaries: No billing, no insurance, no EMR details—just scheduling, queue order, reminders, and daily counts.\n"
12
+ "Constraints: staff have low digital literacy; intermittent internet; must run on existing Android phones; budget is small.\n"
13
+ "Progress strategy: do not dump everything. Reveal details only when asked well. If the student asks leading questions, "
14
+ "correct gently with realistic constraints.\n"
15
+ "When you believe a requirement is sufficiently specified, internally mark that slot as 'filled.'"
16
+ )
17
 
18
  def respond(
19
  message,
 
25
  hf_token: gr.OAuthToken,
26
  ):
27
  """
28
+ For more information on `huggingface_hub` Inference API support, please check the docs:
29
+ https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
30
  """
31
  client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
32
 
33
  messages = [{"role": "system", "content": system_message}]
 
34
  messages.extend(history)
 
35
  messages.append({"role": "user", "content": message})
36
 
37
  response = ""
38
+ for chunk in client.chat_completion(
 
39
  messages,
40
  max_tokens=max_tokens,
41
  stream=True,
42
  temperature=temperature,
43
  top_p=top_p,
44
  ):
45
+ choices = chunk.choices
46
  token = ""
47
  if len(choices) and choices[0].delta.content:
48
  token = choices[0].delta.content
 
49
  response += token
50
  yield response
51
 
52
 
53
+ # ChatInterface with fixed (non-editable) system prompt
 
 
54
  chatbot = gr.ChatInterface(
55
  respond,
56
  type="messages",
57
  additional_inputs=[
58
+ gr.Textbox(
59
+ value=SYSTEM_PROMPT,
60
+ label="System message (locked to Klinik Sehat Sentosa roleplay)",
61
+ interactive=False, # set to True if you want students to edit it
62
+ lines=12,
63
+ ),
64
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
65
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
66
  gr.Slider(
 
78
  gr.LoginButton()
79
  chatbot.render()
80
 
 
81
  if __name__ == "__main__":
82
  demo.launch()