jenbenarye commited on
Commit
e39f857
·
1 Parent(s): 6b3efd9

removed VLMs

Browse files
Files changed (1) hide show
  1. app/app.py +25 -25
app/app.py CHANGED
@@ -70,16 +70,16 @@ CLIENT = create_inference_client()
70
 
71
  def get_persistent_storage_path(filename: str) -> tuple[Path, bool]:
72
  """Check if persistent storage is available and return the appropriate path.
73
-
74
  Args:
75
  filename: The name of the file to check/create
76
-
77
  Returns:
78
  A tuple containing (file_path, is_persistent)
79
  """
80
  persistent_path = Path("/data") / filename
81
  local_path = Path(__file__).parent / filename
82
-
83
  # Check if persistent storage is available and writable
84
  use_persistent = False
85
  if Path("/data").exists() and Path("/data").is_dir():
@@ -92,7 +92,7 @@ def get_persistent_storage_path(filename: str) -> tuple[Path, bool]:
92
  except (PermissionError, OSError):
93
  print("Persistent storage exists but is not writable, falling back to local storage")
94
  use_persistent = False
95
-
96
  return (persistent_path if use_persistent else local_path, use_persistent)
97
 
98
 
@@ -100,7 +100,7 @@ def load_languages() -> dict[str, str]:
100
  """Load languages from JSON file or persistent storage"""
101
  languages_path, use_persistent = get_persistent_storage_path("languages.json")
102
  local_path = Path(__file__).parent / "languages.json"
103
-
104
  # If persistent storage is available but file doesn't exist yet, copy the local file to persistent storage
105
  if use_persistent and not languages_path.exists():
106
  try:
@@ -115,10 +115,10 @@ def load_languages() -> dict[str, str]:
115
  except Exception as e:
116
  print(f"Error setting up persistent storage: {e}")
117
  languages_path = local_path # Fall back to local path if any error occurs
118
-
119
  if not languages_path.exists() and local_path.exists():
120
  languages_path = local_path
121
-
122
  if languages_path.exists():
123
  with open(languages_path, "r", encoding="utf-8") as f:
124
  return json.load(f)
@@ -129,7 +129,7 @@ def load_languages() -> dict[str, str]:
129
  LANGUAGES = load_languages()
130
 
131
  USER_AGREEMENT = """
132
- You have been asked to participate in a research study conducted by Lingo Lab from the Computer Science and Artificial Intelligence Laboratory at the Massachusetts Institute of Technology (M.I.T.), together with huggingface.
133
 
134
  The purpose of this study is the collection of multilingual human feedback to improve language models. As part of this study you will interat with a language model in a langugage of your choice, and provide indication to wether its reponses are helpful or not.
135
 
@@ -268,17 +268,17 @@ def call_pipeline(messages: list, language: str):
268
  if ZERO_GPU:
269
  tokenizer = CLIENT["tokenizer"]
270
  formatted_prompt = tokenizer.apply_chat_template(
271
- messages,
272
- tokenize=False,
273
  )
274
-
275
  response = CLIENT["pipeline"](
276
  formatted_prompt,
277
  clean_up_tokenization_spaces=False,
278
  max_length=2000,
279
  return_full_text=False,
280
  )
281
-
282
  return response[0]["generated_text"]
283
  else:
284
  response = CLIENT(
@@ -299,7 +299,7 @@ def respond(
299
 
300
  Return the history with the new message"""
301
  messages = format_history_as_messages(history)
302
-
303
  if ZERO_GPU:
304
  content = call_pipeline(messages, language)
305
  else:
@@ -311,7 +311,7 @@ def respond(
311
  temperature=temperature,
312
  )
313
  content = response.choices[0].message.content
314
-
315
  message = gr.ChatMessage(role="assistant", content=content)
316
  history.append(message)
317
  return history
@@ -500,29 +500,29 @@ def close_add_language_modal():
500
 
501
  def save_new_language(lang_name, system_prompt):
502
  """Save the new language and system prompt to persistent storage if available, otherwise to local file."""
503
- global LANGUAGES
504
-
505
  languages_path, use_persistent = get_persistent_storage_path("languages.json")
506
  local_path = Path(__file__).parent / "languages.json"
507
-
508
  if languages_path.exists():
509
  with open(languages_path, "r", encoding="utf-8") as f:
510
  data = json.load(f)
511
  else:
512
  data = {}
513
-
514
  data[lang_name] = system_prompt
515
 
516
  with open(languages_path, "w", encoding="utf-8") as f:
517
  json.dump(data, f, ensure_ascii=False, indent=2)
518
-
519
  if use_persistent and local_path != languages_path:
520
  try:
521
  with open(local_path, "w", encoding="utf-8") as f:
522
  json.dump(data, f, ensure_ascii=False, indent=2)
523
  except Exception as e:
524
  print(f"Error updating local backup: {e}")
525
-
526
  LANGUAGES.update({lang_name: system_prompt})
527
  return gr.Group(visible=False), gr.HTML("<script>window.location.reload();</script>"), gr.Dropdown(choices=list(LANGUAGES.keys()))
528
 
@@ -552,14 +552,14 @@ button#add-language-btn {
552
  with gr.Blocks(css=css) as demo:
553
  # State variable to track if user has consented
554
  user_consented = gr.State(False)
555
-
556
  # Landing page with user agreement
557
  with gr.Group(visible=True) as landing_page:
558
  gr.Markdown("# Welcome to FeeL")
559
  with gr.Group(elem_classes=["user-agreement-container"]):
560
  gr.Markdown(USER_AGREEMENT)
561
  consent_btn = gr.Button("I agree")
562
-
563
  # Main application interface (initially hidden)
564
  with gr.Group(visible=False) as main_app:
565
  ##############################
@@ -572,7 +572,7 @@ with gr.Blocks(css=css) as demo:
572
  with gr.Accordion("About") as explanation:
573
  gr.Markdown(f"""
574
  FeeL is a collaboration between Hugging Face and MIT.
575
- It is a community-driven project to provide a real-time feedback loop for VLMs, where your feedback is continuously used to fine-tune the underlying models.
576
  The [dataset](https://huggingface.co/datasets/{scheduler.repo_id}), [code](https://github.com/huggingface/feel) and [models](https://huggingface.co/collections/feel-fl/feel-models-67a9b6ef0fdd554315e295e8) are public.
577
 
578
  Start by selecting your language, chat with the model with text and images and provide feedback in different ways.
@@ -593,7 +593,7 @@ with gr.Blocks(css=css) as demo:
593
  scale=8
594
  )
595
  add_language_btn = gr.Button(
596
- "+",
597
  elem_id="add-language-btn",
598
  size="sm"
599
  )
@@ -719,7 +719,7 @@ with gr.Blocks(css=css) as demo:
719
  global LANGUAGES
720
  LANGUAGES = load_languages()
721
  language_choices = list(LANGUAGES.keys())
722
-
723
  return str(uuid.uuid4()), gr.Dropdown(choices=language_choices, value=language_choices[0])
724
 
725
  demo.load(
 
70
 
71
  def get_persistent_storage_path(filename: str) -> tuple[Path, bool]:
72
  """Check if persistent storage is available and return the appropriate path.
73
+
74
  Args:
75
  filename: The name of the file to check/create
76
+
77
  Returns:
78
  A tuple containing (file_path, is_persistent)
79
  """
80
  persistent_path = Path("/data") / filename
81
  local_path = Path(__file__).parent / filename
82
+
83
  # Check if persistent storage is available and writable
84
  use_persistent = False
85
  if Path("/data").exists() and Path("/data").is_dir():
 
92
  except (PermissionError, OSError):
93
  print("Persistent storage exists but is not writable, falling back to local storage")
94
  use_persistent = False
95
+
96
  return (persistent_path if use_persistent else local_path, use_persistent)
97
 
98
 
 
100
  """Load languages from JSON file or persistent storage"""
101
  languages_path, use_persistent = get_persistent_storage_path("languages.json")
102
  local_path = Path(__file__).parent / "languages.json"
103
+
104
  # If persistent storage is available but file doesn't exist yet, copy the local file to persistent storage
105
  if use_persistent and not languages_path.exists():
106
  try:
 
115
  except Exception as e:
116
  print(f"Error setting up persistent storage: {e}")
117
  languages_path = local_path # Fall back to local path if any error occurs
118
+
119
  if not languages_path.exists() and local_path.exists():
120
  languages_path = local_path
121
+
122
  if languages_path.exists():
123
  with open(languages_path, "r", encoding="utf-8") as f:
124
  return json.load(f)
 
129
  LANGUAGES = load_languages()
130
 
131
  USER_AGREEMENT = """
132
+ You have been asked to participate in a research study conducted by Lingo Lab from the Computer Science and Artificial Intelligence Laboratory at the Massachusetts Institute of Technology (M.I.T.), together with huggingface.
133
 
134
  The purpose of this study is the collection of multilingual human feedback to improve language models. As part of this study you will interat with a language model in a langugage of your choice, and provide indication to wether its reponses are helpful or not.
135
 
 
268
  if ZERO_GPU:
269
  tokenizer = CLIENT["tokenizer"]
270
  formatted_prompt = tokenizer.apply_chat_template(
271
+ messages,
272
+ tokenize=False,
273
  )
274
+
275
  response = CLIENT["pipeline"](
276
  formatted_prompt,
277
  clean_up_tokenization_spaces=False,
278
  max_length=2000,
279
  return_full_text=False,
280
  )
281
+
282
  return response[0]["generated_text"]
283
  else:
284
  response = CLIENT(
 
299
 
300
  Return the history with the new message"""
301
  messages = format_history_as_messages(history)
302
+
303
  if ZERO_GPU:
304
  content = call_pipeline(messages, language)
305
  else:
 
311
  temperature=temperature,
312
  )
313
  content = response.choices[0].message.content
314
+
315
  message = gr.ChatMessage(role="assistant", content=content)
316
  history.append(message)
317
  return history
 
500
 
501
  def save_new_language(lang_name, system_prompt):
502
  """Save the new language and system prompt to persistent storage if available, otherwise to local file."""
503
+ global LANGUAGES
504
+
505
  languages_path, use_persistent = get_persistent_storage_path("languages.json")
506
  local_path = Path(__file__).parent / "languages.json"
507
+
508
  if languages_path.exists():
509
  with open(languages_path, "r", encoding="utf-8") as f:
510
  data = json.load(f)
511
  else:
512
  data = {}
513
+
514
  data[lang_name] = system_prompt
515
 
516
  with open(languages_path, "w", encoding="utf-8") as f:
517
  json.dump(data, f, ensure_ascii=False, indent=2)
518
+
519
  if use_persistent and local_path != languages_path:
520
  try:
521
  with open(local_path, "w", encoding="utf-8") as f:
522
  json.dump(data, f, ensure_ascii=False, indent=2)
523
  except Exception as e:
524
  print(f"Error updating local backup: {e}")
525
+
526
  LANGUAGES.update({lang_name: system_prompt})
527
  return gr.Group(visible=False), gr.HTML("<script>window.location.reload();</script>"), gr.Dropdown(choices=list(LANGUAGES.keys()))
528
 
 
552
  with gr.Blocks(css=css) as demo:
553
  # State variable to track if user has consented
554
  user_consented = gr.State(False)
555
+
556
  # Landing page with user agreement
557
  with gr.Group(visible=True) as landing_page:
558
  gr.Markdown("# Welcome to FeeL")
559
  with gr.Group(elem_classes=["user-agreement-container"]):
560
  gr.Markdown(USER_AGREEMENT)
561
  consent_btn = gr.Button("I agree")
562
+
563
  # Main application interface (initially hidden)
564
  with gr.Group(visible=False) as main_app:
565
  ##############################
 
572
  with gr.Accordion("About") as explanation:
573
  gr.Markdown(f"""
574
  FeeL is a collaboration between Hugging Face and MIT.
575
+ It is a community-driven project to provide a real-time feedback loop for LMs, where your feedback is continuously used to fine-tune the underlying models.
576
  The [dataset](https://huggingface.co/datasets/{scheduler.repo_id}), [code](https://github.com/huggingface/feel) and [models](https://huggingface.co/collections/feel-fl/feel-models-67a9b6ef0fdd554315e295e8) are public.
577
 
578
  Start by selecting your language, chat with the model with text and images and provide feedback in different ways.
 
593
  scale=8
594
  )
595
  add_language_btn = gr.Button(
596
+ "+",
597
  elem_id="add-language-btn",
598
  size="sm"
599
  )
 
719
  global LANGUAGES
720
  LANGUAGES = load_languages()
721
  language_choices = list(LANGUAGES.keys())
722
+
723
  return str(uuid.uuid4()), gr.Dropdown(choices=language_choices, value=language_choices[0])
724
 
725
  demo.load(