Swapnika Dulam commited on
Commit
fb72c6e
·
1 Parent(s): 14aed0a

another issue with decorator and hosting

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -40,8 +40,10 @@ model =None
40
  tokenizer =None
41
  device =None
42
  @spaces.GPU()
43
- def mainblock():
44
  global model, device, tokenizer
 
 
45
  device = "cuda" if torch.cuda.is_available() else "cpu"
46
  dtype = torch.float16 if device == "cuda" else torch.float32
47
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
@@ -80,7 +82,7 @@ def retrieve_context(query, top_k=3):
80
  return "\n\n---\n\n".join(retrieved_chunks)
81
 
82
  def generate_response(context, question, retrieved_context, support_type, support_instruction):
83
-
84
  system_prompt = f"""
85
  You are a mental health support assistant, which answers in any support modes user asks. Here is the overview of support personas, there are five of them.
86
  Informational Support Persona: Provides factual information, practical advice, and actionable guidance to help solve problems.
@@ -264,7 +266,7 @@ button[aria-label="Copy all"] {
264
  """
265
 
266
  with gr.Blocks() as demo:
267
- mainblock()
268
  gr.Markdown("## Support Chatbot")
269
  gr.Markdown("Choose a support type and chat for your session.")
270
  support_type = gr.Radio(
 
40
  tokenizer =None
41
  device =None
42
  @spaces.GPU()
43
+ def initModel():
44
  global model, device, tokenizer
45
+ if model is not None and tokenizer is not None and device is not None:
46
+ return
47
  device = "cuda" if torch.cuda.is_available() else "cpu"
48
  dtype = torch.float16 if device == "cuda" else torch.float32
49
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
 
82
  return "\n\n---\n\n".join(retrieved_chunks)
83
 
84
  def generate_response(context, question, retrieved_context, support_type, support_instruction):
85
+ initModel()
86
  system_prompt = f"""
87
  You are a mental health support assistant, which answers in any support modes user asks. Here is the overview of support personas, there are five of them.
88
  Informational Support Persona: Provides factual information, practical advice, and actionable guidance to help solve problems.
 
266
  """
267
 
268
  with gr.Blocks() as demo:
269
+
270
  gr.Markdown("## Support Chatbot")
271
  gr.Markdown("Choose a support type and chat for your session.")
272
  support_type = gr.Radio(