reedmayhew commited on
Commit
e0a81d3
·
verified ·
1 Parent(s): 7fd2cf6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -17
app.py CHANGED
@@ -15,7 +15,9 @@ DESCRIPTION = '''
15
 
16
  LICENSE = """
17
  <p>
18
- This Health Assistant is designed to provide helpful healthcare information; however, it may make mistakes and is not designed to replace professional medical care. It is not intended to diagnose any condition or disease. Always consult with a qualified healthcare provider for any medical concerns.\n\nI hereby confirm that I am at least 18 years of age (or accompanied by a legal guardian who is at least 18 years old), understand that the information provided by this service is for informational purposes only and is not intended to diagnose or treat any medical condition, and acknowledge that I am solely responsible for verifying any information provided.
 
 
19
  </p>
20
  """
21
 
@@ -57,13 +59,6 @@ def chat_llama3_8b(message: str,
57
  ) -> str:
58
  """
59
  Generate a streaming response using the llama3-8b model.
60
- Args:
61
- message (str): The input message.
62
- history (list): The conversation history used by ChatInterface.
63
- temperature (float): The temperature for generating the response.
64
- max_new_tokens (int): The maximum number of new tokens to generate.
65
- Returns:
66
- str: The generated response.
67
  """
68
 
69
  conversation = []
@@ -123,12 +118,30 @@ def chat_llama3_8b(message: str,
123
  # Store the full response (including <think>) in history, but only show the user the cleaned response
124
  history.append((message, full_response)) # Full assistant response saved for context
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  # Gradio block
127
  chatbot = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
128
 
129
  with gr.Blocks(fill_height=True, css=css) as demo:
130
-
131
  gr.Markdown(DESCRIPTION)
 
 
 
 
132
  gr.ChatInterface(
133
  fn=chat_llama3_8b,
134
  chatbot=chatbot,
@@ -138,17 +151,23 @@ with gr.Blocks(fill_height=True, css=css) as demo:
138
  gr.Slider(minimum=0.6, maximum=0.6, step=0.1, value=0.6, label="Temperature", render=False),
139
  gr.Slider(minimum=1024, maximum=4096, step=128, value=2048, label="Max new tokens", render=False),
140
  ],
141
- examples=[
142
- ['What is PrEP, and do I need it?'],
143
- ['What medications help manage being undetectable with HIV?'],
144
- ['How do I know if an abortion is the right option?'],
145
- ['How can I access birth-control in states where it is regulated?']
146
  cache_examples=False,
147
- ]
148
-
149
  )
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  gr.Markdown(LICENSE)
152
 
153
  if __name__ == "__main__":
154
- demo.launch()
 
15
 
16
  LICENSE = """
17
  <p>
18
+ This Health Assistant is designed to provide helpful healthcare information; however, it may make mistakes and is not designed to replace professional medical care. It is not intended to diagnose any condition or disease. Always consult with a qualified healthcare provider for any medical concerns.
19
+ <br><br>
20
+ I hereby confirm that I am at least 18 years of age (or accompanied by a legal guardian who is at least 18 years old), understand that the information provided by this service is for informational purposes only and is not intended to diagnose or treat any medical condition, and acknowledge that I am solely responsible for verifying any information provided.
21
  </p>
22
  """
23
 
 
59
  ) -> str:
60
  """
61
  Generate a streaming response using the llama3-8b model.
 
 
 
 
 
 
 
62
  """
63
 
64
  conversation = []
 
118
  # Store the full response (including <think>) in history, but only show the user the cleaned response
119
  history.append((message, full_response)) # Full assistant response saved for context
120
 
121
+ # JavaScript snippet that checks the URL for ?examples=true and toggles the visibility of the examples container.
122
+ js_code = """
123
+ <script>
124
+ window.addEventListener("load", function(){
125
+ const urlParams = new URLSearchParams(window.location.search);
126
+ if(urlParams.get('examples') !== 'true'){
127
+ var elem = document.getElementById("examples-container");
128
+ if (elem) {
129
+ elem.style.display = "none";
130
+ }
131
+ }
132
+ });
133
+ </script>
134
+ """
135
+
136
  # Gradio block
137
  chatbot = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
138
 
139
  with gr.Blocks(fill_height=True, css=css) as demo:
 
140
  gr.Markdown(DESCRIPTION)
141
+
142
+ # Include the JavaScript in an HTML block so it runs on the client side.
143
+ gr.HTML(js_code)
144
+
145
  gr.ChatInterface(
146
  fn=chat_llama3_8b,
147
  chatbot=chatbot,
 
151
  gr.Slider(minimum=0.6, maximum=0.6, step=0.1, value=0.6, label="Temperature", render=False),
152
  gr.Slider(minimum=1024, maximum=4096, step=128, value=2048, label="Max new tokens", render=False),
153
  ],
 
 
 
 
 
154
  cache_examples=False,
 
 
155
  )
156
 
157
+ # Wrap your examples in a container with an id.
158
+ with gr.Column(elem_id="examples-container"):
159
+ gr.Markdown("### Examples")
160
+ gr.Examples(
161
+ examples=[
162
+ ['What is PrEP, and do I need it?'],
163
+ ['What medications help manage being undetectable with HIV?'],
164
+ ['How do I know if an abortion is the right option?'],
165
+ ['How can I access birth-control in states where it is regulated?']
166
+ ],
167
+ inputs=chatbot,
168
+ )
169
+
170
  gr.Markdown(LICENSE)
171
 
172
  if __name__ == "__main__":
173
+ demo.launch()