Tonic commited on
Commit
5ff99f2
1 Parent(s): 8eb345d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -30
app.py CHANGED
@@ -60,34 +60,23 @@ class FalconChatBot:
60
  filtered_history.append({"user": user_message, "assistant": assistant_message})
61
  return filtered_history
62
 
63
- def predict(self, system_prompt, user_message, assistant_message, history, temperature=temperature, max_new_tokens=max_new_tokens, top_p=top_p, repetition_penalty=repetition_penalty):
64
 
65
  # Process the history to remove special commands
66
- processed_history = self.process_history(history)
67
-
68
  # Combine the user and assistant messages into a conversation
69
- conversation = f"{system_prompt}\nFalcon: {assistant_message if assistant_message else ''} User: {user_message}\nFalcon:\n"
70
-
71
  # Encode the conversation using the tokenizer
72
- input_ids = tokenizer.encode(conversation, return_tensors="pt", add_special_tokens=False)
73
-
74
  # Generate a response using the Falcon model
75
- response_text = peft_model.generate(input_ids=input_ids, max_length=max_length, use_cache=True, early_stopping=True, bos_token_id=peft_model.config.bos_token_id, eos_token_id=peft_model.config.eos_token_id, pad_token_id=peft_model.config.eos_token_id, temperature=0.4, do_sample=True)
76
-
77
- # Generate the formatted conversation in Falcon message format
78
- conversation = f"{system_prompt}\n"
79
- for message in processed_history:
80
- user_message = message["user"]
81
- assistant_message = message["assistant"]
82
- conversation += f"Falcon:{' ' + assistant_message if assistant_message else ''} User: {user_message}\n Falcon:\n"
83
  # Decode the generated response to text
84
- response_text = tokenizer.decode(response[0], skip_special_tokens=True)
85
-
86
  # Append the Falcon-like conversation to the history
87
- self.history.append(formatted_input)
88
- self.history.append(response_text)
89
-
90
- return response_text
91
 
92
 
93
  # Create the Falcon chatbot instance
@@ -99,17 +88,11 @@ description = "You can use this Space to test out the GaiaMiniMed model [(Tonic/
99
 
100
  examples = [
101
  [
102
- "Assistant is a public health and medical expert ready to help the user.",
103
  "Hi there, I have a question!",
104
  "My name is Gaia, I'm a health and sanitation expert ready to answer your medical questions.",
105
- "", 0.4, 500, 0.94, 1.9
106
- ],
107
- [
108
- "Assistant is a public health and medical expert ready to help the user.",
109
- "What is the proper treatment for buccal herpes?",
110
- None,
111
- "", 0.2, 500, 0.92, 1.7
112
- ]
113
  ]
114
 
115
 
 
60
  filtered_history.append({"user": user_message, "assistant": assistant_message})
61
  return filtered_history
62
 
63
+ def predict(self, user_message, assistant_message, history, temperature=temperature, max_new_tokens=max_new_tokens, top_p=top_p, repetition_penalty=repetition_penalty):
64
 
65
  # Process the history to remove special commands
66
+ processed_history = self.process_history(history)
 
67
  # Combine the user and assistant messages into a conversation
68
+ conversation = f"{self.system_prompt}\nFalcon: {assistant_message if assistant_message else ''} User: {user_message}\nFalcon:\n"
 
69
  # Encode the conversation using the tokenizer
70
+ input_ids = tokenizer.encode(conversation, return_tensors="pt", add_special_tokens=False)
 
71
  # Generate a response using the Falcon model
72
+ response = peft_model.generate(input_ids=input_ids, max_length=max_length, use_cache=False, early_stopping=False, bos_token_id=peft_model.config.bos_token_id, eos_token_id=peft_model.config.eos_token_id, pad_token_id=peft_model.config.eos_token_id, temperature=0.4, do_sample=True)
 
 
 
 
 
 
 
73
  # Decode the generated response to text
74
+ response_text = tokenizer.decode(response[0], skip_special_tokens=True)
 
75
  # Append the Falcon-like conversation to the history
76
+ self.history.append(conversation)
77
+ self.history.append(response_text)
78
+
79
+ return response_text
80
 
81
 
82
  # Create the Falcon chatbot instance
 
88
 
89
  examples = [
90
  [
91
+ "Assistant is a public health and medical expert named Gaia ready to help the user.",
92
  "Hi there, I have a question!",
93
  "My name is Gaia, I'm a health and sanitation expert ready to answer your medical questions.",
94
+ "Assistant is a medical and sanitation question expert trained to answer medical questions", 0.4, 700, 0.90, 1.9
95
+ ]
 
 
 
 
 
 
96
  ]
97
 
98