Update app.py
Browse files
app.py
CHANGED
|
@@ -36,10 +36,11 @@ class SynthIDApp:
|
|
| 36 |
params = {
|
| 37 |
"inputs": text,
|
| 38 |
"parameters": {
|
| 39 |
-
"
|
| 40 |
"do_sample": True,
|
| 41 |
"temperature": 0.7,
|
| 42 |
"top_p": 0.9,
|
|
|
|
| 43 |
"watermarking_config": {
|
| 44 |
"keys": self.WATERMARK_KEYS,
|
| 45 |
"ngram_len": int(ngram_len) # Ensure integer
|
|
@@ -55,12 +56,16 @@ class SynthIDApp:
|
|
| 55 |
)
|
| 56 |
response.raise_for_status()
|
| 57 |
|
| 58 |
-
# Extract the
|
| 59 |
result = response.json()
|
| 60 |
if isinstance(result, list) and len(result) > 0:
|
| 61 |
-
watermarked_text = result[0].get('generated_text',
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
else:
|
| 63 |
-
|
| 64 |
|
| 65 |
return watermarked_text, f"Watermark applied successfully! (ngram_len: {ngram_len})"
|
| 66 |
except Exception as e:
|
|
@@ -108,7 +113,8 @@ with gr.Blocks(title="SynthID Text Watermarking Tool") as app:
|
|
| 108 |
input_text = gr.Textbox(
|
| 109 |
label="Input Text",
|
| 110 |
lines=5,
|
| 111 |
-
placeholder="Enter text to watermark..."
|
|
|
|
| 112 |
)
|
| 113 |
output_text = gr.Textbox(label="Watermarked Text", lines=5)
|
| 114 |
with gr.Column(scale=1):
|
|
|
|
| 36 |
params = {
|
| 37 |
"inputs": text,
|
| 38 |
"parameters": {
|
| 39 |
+
"return_full_text": True,
|
| 40 |
"do_sample": True,
|
| 41 |
"temperature": 0.7,
|
| 42 |
"top_p": 0.9,
|
| 43 |
+
"max_length": None, # Use input length
|
| 44 |
"watermarking_config": {
|
| 45 |
"keys": self.WATERMARK_KEYS,
|
| 46 |
"ngram_len": int(ngram_len) # Ensure integer
|
|
|
|
| 56 |
)
|
| 57 |
response.raise_for_status()
|
| 58 |
|
| 59 |
+
# Extract the watermarked text
|
| 60 |
result = response.json()
|
| 61 |
if isinstance(result, list) and len(result) > 0:
|
| 62 |
+
watermarked_text = result[0].get('generated_text', '')
|
| 63 |
+
if not watermarked_text:
|
| 64 |
+
return text, "Error: No watermarked text generated"
|
| 65 |
+
# Clean up any extra whitespace
|
| 66 |
+
watermarked_text = watermarked_text.strip()
|
| 67 |
else:
|
| 68 |
+
return text, "Error: Unexpected API response format"
|
| 69 |
|
| 70 |
return watermarked_text, f"Watermark applied successfully! (ngram_len: {ngram_len})"
|
| 71 |
except Exception as e:
|
|
|
|
| 113 |
input_text = gr.Textbox(
|
| 114 |
label="Input Text",
|
| 115 |
lines=5,
|
| 116 |
+
placeholder="Enter text to watermark...",
|
| 117 |
+
value="The quick brown fox jumps over the lazy dog."
|
| 118 |
)
|
| 119 |
output_text = gr.Textbox(label="Watermarked Text", lines=5)
|
| 120 |
with gr.Column(scale=1):
|