kkruel8100 commited on
Commit
2997374
1 Parent(s): ac3ce50

update model

Browse files
Files changed (1) hide show
  1. app.py +1 -35
app.py CHANGED
@@ -19,12 +19,8 @@ import os
19
  from langchain.schema import HumanMessage, SystemMessage
20
  from langchain_openai import ChatOpenAI
21
 
22
-
23
- # In[18]:
24
-
25
-
26
  # Set the model's file path
27
- file_path = Path("models/model_adam_scaled.h5")
28
 
29
  # Load the model to a new object
30
  adam_5 = tf.keras.models.load_model(file_path)
@@ -37,7 +33,6 @@ openai_api_key = os.getenv("OPENAI_API_KEY")
37
 
38
  print(f"OpenAI API Key Loaded: {openai_api_key is not None}")
39
 
40
-
41
  # Load the model and tokenizer for translation
42
  model = MBartForConditionalGeneration.from_pretrained(
43
  "facebook/mbart-large-50-many-to-many-mmt"
@@ -49,10 +44,6 @@ tokenizer = MBart50TokenizerFast.from_pretrained(
49
  # Set source language
50
  tokenizer.src_lang = "en_XX"
51
 
52
-
53
- # In[22]:
54
-
55
-
56
  # Constants
57
  # Language information MBart
58
  language_info = [
@@ -129,19 +120,12 @@ default_language = "English"
129
  malignant_text = "Malignant. Please consult a doctor for further evaluation."
130
  benign_text = "Benign. Please consult a doctor for further evaluation."
131
 
132
-
133
- # In[23]:
134
-
135
-
136
  # Create instance
137
  llm = ChatOpenAI(
138
  openai_api_key=openai_api_key, model_name="gpt-3.5-turbo", temperature=0
139
  )
140
 
141
 
142
- # In[24]:
143
-
144
-
145
  # Method to get system and human messages for ChatOpenAI - Predictions
146
  def get_prediction_messages(prediction_text):
147
  # Create a HumanMessage object
@@ -156,9 +140,6 @@ def get_prediction_messages(prediction_text):
156
  return [system_message, human_message]
157
 
158
 
159
- # In[25]:
160
-
161
-
162
  # Method to get system and human messages for ChatOpenAI - Help
163
  def get_chat_messages(chat_prompt):
164
  # Create a HumanMessage object
@@ -172,9 +153,6 @@ def get_chat_messages(chat_prompt):
172
  return [system_message, human_message]
173
 
174
 
175
- # In[26]:
176
-
177
-
178
  # Method to predict the image
179
  def predict_image(language, img):
180
  try:
@@ -264,9 +242,6 @@ def predict_image(language, img):
264
  )
265
 
266
 
267
- # In[27]:
268
-
269
-
270
  # Method for on submit
271
  def on_submit(language, img):
272
  print(f"Language: {language}")
@@ -283,9 +258,6 @@ def on_submit(language, img):
283
  return predict_image(language, img)
284
 
285
 
286
- # In[28]:
287
-
288
-
289
  # Method for on clear
290
  def on_clear():
291
  return (
@@ -299,9 +271,6 @@ def on_clear():
299
  )
300
 
301
 
302
- # In[29]:
303
-
304
-
305
  # Method for on chat
306
  def on_chat(language, chat_prompt):
307
  try:
@@ -351,9 +320,6 @@ def on_chat(language, chat_prompt):
351
  )
352
 
353
 
354
- # In[30]:
355
-
356
-
357
  # Gradio app
358
 
359
  with gr.Blocks(theme=gr.themes.Default(primary_hue="green")) as demo:
 
19
  from langchain.schema import HumanMessage, SystemMessage
20
  from langchain_openai import ChatOpenAI
21
 
 
 
 
 
22
  # Set the model's file path
23
+ file_path = Path("models/model_adam_5.h5")
24
 
25
  # Load the model to a new object
26
  adam_5 = tf.keras.models.load_model(file_path)
 
33
 
34
  print(f"OpenAI API Key Loaded: {openai_api_key is not None}")
35
 
 
36
  # Load the model and tokenizer for translation
37
  model = MBartForConditionalGeneration.from_pretrained(
38
  "facebook/mbart-large-50-many-to-many-mmt"
 
44
  # Set source language
45
  tokenizer.src_lang = "en_XX"
46
 
 
 
 
 
47
  # Constants
48
  # Language information MBart
49
  language_info = [
 
120
  malignant_text = "Malignant. Please consult a doctor for further evaluation."
121
  benign_text = "Benign. Please consult a doctor for further evaluation."
122
 
 
 
 
 
123
  # Create instance
124
  llm = ChatOpenAI(
125
  openai_api_key=openai_api_key, model_name="gpt-3.5-turbo", temperature=0
126
  )
127
 
128
 
 
 
 
129
  # Method to get system and human messages for ChatOpenAI - Predictions
130
  def get_prediction_messages(prediction_text):
131
  # Create a HumanMessage object
 
140
  return [system_message, human_message]
141
 
142
 
 
 
 
143
  # Method to get system and human messages for ChatOpenAI - Help
144
  def get_chat_messages(chat_prompt):
145
  # Create a HumanMessage object
 
153
  return [system_message, human_message]
154
 
155
 
 
 
 
156
  # Method to predict the image
157
  def predict_image(language, img):
158
  try:
 
242
  )
243
 
244
 
 
 
 
245
  # Method for on submit
246
  def on_submit(language, img):
247
  print(f"Language: {language}")
 
258
  return predict_image(language, img)
259
 
260
 
 
 
 
261
  # Method for on clear
262
  def on_clear():
263
  return (
 
271
  )
272
 
273
 
 
 
 
274
  # Method for on chat
275
  def on_chat(language, chat_prompt):
276
  try:
 
320
  )
321
 
322
 
 
 
 
323
  # Gradio app
324
 
325
  with gr.Blocks(theme=gr.themes.Default(primary_hue="green")) as demo: