hallisky commited on
Commit
c4d01dc
Β·
1 Parent(s): 73d39e7

Fix saving feedback

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -12,6 +12,8 @@ from huggingface_hub import CommitScheduler
12
 
13
  # TODO make it so that feedback is only saved on prev. example if user makes another obfuscation
14
  # and changes slider but doesn't hit obfuscate
 
 
15
 
16
  MODEL_PATHS = {
17
  "length_more": "hallisky/lora-length-long-llama-3-8b",
@@ -24,7 +26,7 @@ MODEL_PATHS = {
24
 
25
  DESCRIPTION = """\
26
  # Authorship Obfuscation
27
- This Space demonstrates model [Llama-2-7b-chat](https://huggingface.co/meta-llama/Llama-2-7b-chat) by Meta, a Llama 2 model with 7B parameters fine-tuned for chat instructions. Feel free to play with it, or duplicate to run generations without a queue! If you want to run your own service, you can also [deploy the model on Inference Endpoints](https://huggingface.co/inference-endpoints).
28
  πŸ”Ž For more details about the Llama 2 family of models and how to use them with `transformers`, take a look [at our blog post](https://huggingface.co/blog/llama2).
29
  πŸ”¨ Looking for an even more powerful model? Check out the [13B version](https://huggingface.co/spaces/huggingface-projects/llama-2-13b-chat) or the large [70B model demo](https://huggingface.co/spaces/ysharma/Explore_llamav2_with_TGI).
30
  """
@@ -41,7 +43,6 @@ if torch.cuda.is_available():
41
  tokenizer = AutoTokenizer.from_pretrained(model_id)
42
 
43
  # Global variable to store the latest obfuscation result
44
- latest_obfuscation = {}
45
  user_id = str(uuid4()) # Generate a unique session-specific user ID
46
 
47
  JSON_DATASET_DIR = Path("json_dataset")
@@ -63,13 +64,10 @@ def save_data(data):
63
  json.dump(data, f)
64
  f.write("\n")
65
 
66
- def save_feedback(feedback_rating, feedback_text):
67
- global latest_obfuscation
68
- if latest_obfuscation:
69
- feedback_data = latest_obfuscation.copy()
70
- feedback_data["feedback_rating"] = feedback_rating
71
- feedback_data["feedback_text"] = feedback_text
72
- save_data(feedback_data)
73
  return "No Feedback Selected", ""
74
 
75
  @spaces.GPU
@@ -125,7 +123,7 @@ def greet(input_text, length, function_words, grade_level, sarcasm, formality, v
125
  # Save the obfuscation result
126
  save_data(latest_obfuscation)
127
 
128
- return response, gr.update(interactive=True), gr.update(interactive=True)
129
 
130
  def reset_sliders():
131
  return [0.5] * 7 + [0] * 3
@@ -161,6 +159,7 @@ def check_initial_feedback_state(feedback_rating, feedback_text):
161
  demo = gr.Blocks()
162
 
163
  with demo:
 
164
  gr.Markdown(DESCRIPTION)
165
  with gr.Row():
166
  with gr.Column(variant="panel"):
@@ -242,7 +241,10 @@ with demo:
242
  gr.Markdown("### Provide any feedback on the obfuscation")
243
  feedback_text = gr.Textbox(label="Feedback", lines=3, interactive=False)
244
 
245
- obfuscate_button.click(fn=greet, inputs=[input_text] + sliders, outputs=[output, feedback_rating, feedback_text])
 
 
 
246
 
247
  save_feedback_button = gr.Button("Save Feedback", interactive=False)
248
  feedback_warning_message = gr.Markdown(
@@ -255,7 +257,7 @@ with demo:
255
 
256
  save_feedback_button.click(
257
  fn=save_feedback,
258
- inputs=[feedback_rating, feedback_text],
259
  outputs=[feedback_rating, feedback_text]
260
  )
261
  # Initialize the save feedback button and warning message state on page load
 
12
 
13
  # TODO make it so that feedback is only saved on prev. example if user makes another obfuscation
14
  # and changes slider but doesn't hit obfuscate
15
+ # TODO maybe make it save and reset if user hits submit feedback
16
+ # TODO sampling params for modles
17
 
18
  MODEL_PATHS = {
19
  "length_more": "hallisky/lora-length-long-llama-3-8b",
 
26
 
27
  DESCRIPTION = """\
28
  # Authorship Obfuscation
29
+ This Space demonstrates StyleRemix, a Llama 3 model with 8B parameters fine-tuned for chat instructions. Feel free to play with it, or duplicate to run generations without a queue! If you want to run your own service, you can also [deploy the model on Inference Endpoints](https://huggingface.co/inference-endpoints).
30
  πŸ”Ž For more details about the Llama 2 family of models and how to use them with `transformers`, take a look [at our blog post](https://huggingface.co/blog/llama2).
31
  πŸ”¨ Looking for an even more powerful model? Check out the [13B version](https://huggingface.co/spaces/huggingface-projects/llama-2-13b-chat) or the large [70B model demo](https://huggingface.co/spaces/ysharma/Explore_llamav2_with_TGI).
32
  """
 
43
  tokenizer = AutoTokenizer.from_pretrained(model_id)
44
 
45
  # Global variable to store the latest obfuscation result
 
46
  user_id = str(uuid4()) # Generate a unique session-specific user ID
47
 
48
  JSON_DATASET_DIR = Path("json_dataset")
 
64
  json.dump(data, f)
65
  f.write("\n")
66
 
67
+ def save_feedback(feedback_rating, feedback_text, latest_obfuscation):
68
+ latest_obfuscation["feedback_rating"] = feedback_rating
69
+ latest_obfuscation["feedback_text"] = feedback_text
70
+ save_data(latest_obfuscation)
 
 
 
71
  return "No Feedback Selected", ""
72
 
73
  @spaces.GPU
 
123
  # Save the obfuscation result
124
  save_data(latest_obfuscation)
125
 
126
+ return response, gr.update(interactive=True), gr.update(interactive=True), latest_obfuscation
127
 
128
  def reset_sliders():
129
  return [0.5] * 7 + [0] * 3
 
159
  demo = gr.Blocks()
160
 
161
  with demo:
162
+ latest_obfuscation = gr.State({})
163
  gr.Markdown(DESCRIPTION)
164
  with gr.Row():
165
  with gr.Column(variant="panel"):
 
241
  gr.Markdown("### Provide any feedback on the obfuscation")
242
  feedback_text = gr.Textbox(label="Feedback", lines=3, interactive=False)
243
 
244
+ obfuscate_button.click(
245
+ fn=greet,
246
+ inputs=[input_text] + sliders,
247
+ outputs=[output, feedback_rating, feedback_text, latest_obfuscation])
248
 
249
  save_feedback_button = gr.Button("Save Feedback", interactive=False)
250
  feedback_warning_message = gr.Markdown(
 
257
 
258
  save_feedback_button.click(
259
  fn=save_feedback,
260
+ inputs=[feedback_rating, feedback_text, latest_obfuscation],
261
  outputs=[feedback_rating, feedback_text]
262
  )
263
  # Initialize the save feedback button and warning message state on page load