Tonic commited on
Commit
e6521eb
Β·
1 Parent(s): 81e67ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -3,7 +3,6 @@ import torch
3
  import gradio as gr
4
  import os
5
 
6
- hf_token = os.environ.get('HUGGINGFACE_TOKEN')
7
 
8
  # Define the device
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -21,10 +20,9 @@ model.to(device)
21
  class ChatBot:
22
  def __init__(self):
23
  self.history = []
24
- def predict(self, user_input, system_prompt="You are an expert medical analyst:"):
25
- formatted_prompt = f"{user_input}\n{system_prompt}:"
26
- prompt = [{'role': 'user', 'content': formatted_prompt}]
27
- prompt = [{'role': 'user', 'content': user_input "\n" system_prompt}]
28
  inputs = tokenizer.apply_chat_template(
29
  prompt,
30
  add_generation_prompt=True,
@@ -39,13 +37,13 @@ class ChatBot:
39
  do_sample=False
40
  )
41
 
42
- # Decode and return the response
43
  response_text = tokenizer.decode(tokens[0], skip_special_tokens=False)
44
- return response_text
45
-
46
  # Free up memory
47
  del tokens
48
  torch.cuda.empty_cache()
 
49
  return response_text
50
 
51
  bot = ChatBot()
@@ -63,7 +61,7 @@ iface = gr.Interface(
63
  title=title,
64
  description=description,
65
  examples=examples,
66
- inputs=["text", "text"], # Take user input and system prompt separately
67
  outputs="text",
68
  theme="ParityError/Anime"
69
  )
 
3
  import gradio as gr
4
  import os
5
 
 
6
 
7
  # Define the device
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
20
  class ChatBot:
21
  def __init__(self):
22
  self.history = []
23
+
24
+ def predict(self, user_input, system_prompt="You are an expert analyst and provide assessment:"):
25
+ prompt = [{'role': 'user', 'content': user_input + "\n" + system_prompt + ":"}]
 
26
  inputs = tokenizer.apply_chat_template(
27
  prompt,
28
  add_generation_prompt=True,
 
37
  do_sample=False
38
  )
39
 
40
+ # Decode the response
41
  response_text = tokenizer.decode(tokens[0], skip_special_tokens=False)
42
+
 
43
  # Free up memory
44
  del tokens
45
  torch.cuda.empty_cache()
46
+
47
  return response_text
48
 
49
  bot = ChatBot()
 
61
  title=title,
62
  description=description,
63
  examples=examples,
64
+ inputs=["text", "text"],
65
  outputs="text",
66
  theme="ParityError/Anime"
67
  )