simar007 commited on
Commit
6c52600
·
verified ·
1 Parent(s): da75924

Update fake.py

Browse files
Files changed (1) hide show
  1. fake.py +39 -3
fake.py CHANGED
@@ -2,14 +2,50 @@ import gradio as gr
2
  import spaces
3
  import transformers_gradio
4
 
5
- demo = gr.load(name="google/gemma-3-1b-it", src=transformers_gradio.registry)
6
  demo = gr.load(name="unsloth/gemma-3-1b-it-GGUF", src=transformers_gradio.registry)
7
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- demo.fn = spaces.GPU()(demo.fn)
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  for fn in demo.fns.values():
12
  fn.api_name = False
13
 
 
 
 
 
14
  if __name__ == "__main__":
15
- demo.launch()
 
2
  import spaces
3
  import transformers_gradio
4
 
5
+ # Load the model interface
6
  demo = gr.load(name="unsloth/gemma-3-1b-it-GGUF", src=transformers_gradio.registry)
7
 
8
+ # -------------------------------
9
+ # 1. Custom doctor system prompt
10
+ # -------------------------------
11
+ DOCTOR_SYSTEM_PROMPT = """
12
+ You are DoctorAI, a helpful, calm, and safe medical assistant.
13
+ Give educational medical explanations.
14
+ Do NOT give diagnoses.
15
+ Do NOT prescribe treatments.
16
+ Always advise seeing a medical professional for anything serious.
17
+ """
18
 
 
19
 
20
+ # ---------------------------------------------------
21
+ # 2. Wrap original fn so doctor prompt is added
22
+ # ---------------------------------------------------
23
+ original_fn = demo.fn
24
+
25
+ def doctor_wrapper(*args, **kwargs):
26
+ """
27
+ Intercepts user input and adds your custom doctor system prompt
28
+ before sending to the model.
29
+ """
30
+ # Usually args[0] is the user message in gradio chat interfaces
31
+ if len(args) > 0:
32
+ user_message = args[0]
33
+ new_message = DOCTOR_SYSTEM_PROMPT + "\n\nUser: " + user_message
34
+ args = (new_message,) + args[1:]
35
+
36
+ return original_fn(*args, **kwargs)
37
+
38
+
39
+ # Replace the model fn with your wrapped version
40
+ demo.fn = spaces.GPU()(doctor_wrapper)
41
+
42
+ # Hide the API names
43
  for fn in demo.fns.values():
44
  fn.api_name = False
45
 
46
+
47
+ # ---------------------------------------------------
48
+ # 3. Launch
49
+ # ---------------------------------------------------
50
  if __name__ == "__main__":
51
+ demo.launch()