Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
| 1 |
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
import torch
|
| 6 |
|
| 7 |
-
|
| 8 |
class ModelProcessor:
|
| 9 |
def __init__(self, repo_id="HuggingFaceTB/cosmo-1b"):
|
| 10 |
self.device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
@@ -20,7 +18,6 @@ class ModelProcessor:
|
|
| 20 |
# Set padding token as end-of-sequence token
|
| 21 |
self.tokenizer.pad_token = self.tokenizer.eos_token
|
| 22 |
|
| 23 |
-
|
| 24 |
@torch.inference_mode()
|
| 25 |
def process_data_and_compute_statistics(self, prompt):
|
| 26 |
# Tokenize the prompt and move to the device
|
|
@@ -64,7 +61,6 @@ class ModelProcessor:
|
|
| 64 |
|
| 65 |
return 1 if (ranks.clamp(max=4) * nll.clamp(max=4)).mean() < 5.2 else 0
|
| 66 |
|
| 67 |
-
|
| 68 |
processor = ModelProcessor()
|
| 69 |
|
| 70 |
@spaces.GPU(duration=180)
|
|
@@ -75,7 +71,6 @@ def detect(prompt):
|
|
| 75 |
else:
|
| 76 |
return "The text is likely **not generated** by a language model."
|
| 77 |
|
| 78 |
-
|
| 79 |
with gr.Blocks(
|
| 80 |
css="""
|
| 81 |
.gradio-container {
|
|
@@ -89,14 +84,21 @@ with gr.Blocks(
|
|
| 89 |
}
|
| 90 |
.gr-button {
|
| 91 |
background-color: #007bff;
|
| 92 |
-
color: white;
|
|
|
|
| 93 |
border-radius: 4px;
|
| 94 |
}
|
| 95 |
.gr-button:hover {
|
| 96 |
-
background-color:
|
|
|
|
| 97 |
.hyperlinks a {
|
| 98 |
margin-right: 10px;
|
| 99 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
"""
|
| 101 |
) as demo:
|
| 102 |
with gr.Row():
|
|
@@ -116,7 +118,7 @@ with gr.Blocks(
|
|
| 116 |
label="Prompt",
|
| 117 |
)
|
| 118 |
submit_btn = gr.Button("Submit", variant="primary")
|
| 119 |
-
output = gr.Markdown()
|
| 120 |
|
| 121 |
submit_btn.click(fn=detect, inputs=prompt, outputs=output)
|
| 122 |
|
|
|
|
| 1 |
import spaces
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
import torch
|
| 5 |
|
|
|
|
| 6 |
class ModelProcessor:
|
| 7 |
def __init__(self, repo_id="HuggingFaceTB/cosmo-1b"):
|
| 8 |
self.device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 18 |
# Set padding token as end-of-sequence token
|
| 19 |
self.tokenizer.pad_token = self.tokenizer.eos_token
|
| 20 |
|
|
|
|
| 21 |
@torch.inference_mode()
|
| 22 |
def process_data_and_compute_statistics(self, prompt):
|
| 23 |
# Tokenize the prompt and move to the device
|
|
|
|
| 61 |
|
| 62 |
return 1 if (ranks.clamp(max=4) * nll.clamp(max=4)).mean() < 5.2 else 0
|
| 63 |
|
|
|
|
| 64 |
processor = ModelProcessor()
|
| 65 |
|
| 66 |
@spaces.GPU(duration=180)
|
|
|
|
| 71 |
else:
|
| 72 |
return "The text is likely **not generated** by a language model."
|
| 73 |
|
|
|
|
| 74 |
with gr.Blocks(
|
| 75 |
css="""
|
| 76 |
.gradio-container {
|
|
|
|
| 84 |
}
|
| 85 |
.gr-button {
|
| 86 |
background-color: #007bff;
|
| 87 |
+
color: white;
|
| 88 |
+
padding: 10px 20px;
|
| 89 |
border-radius: 4px;
|
| 90 |
}
|
| 91 |
.gr-button:hover {
|
| 92 |
+
background-color: #0056b3;
|
| 93 |
+
}
|
| 94 |
.hyperlinks a {
|
| 95 |
margin-right: 10px;
|
| 96 |
}
|
| 97 |
+
.output-text {
|
| 98 |
+
text-align: center;
|
| 99 |
+
font-size: 24px;
|
| 100 |
+
font-weight: bold;
|
| 101 |
+
}
|
| 102 |
"""
|
| 103 |
) as demo:
|
| 104 |
with gr.Row():
|
|
|
|
| 118 |
label="Prompt",
|
| 119 |
)
|
| 120 |
submit_btn = gr.Button("Submit", variant="primary")
|
| 121 |
+
output = gr.Markdown(elem_id="output-text")
|
| 122 |
|
| 123 |
submit_btn.click(fn=detect, inputs=prompt, outputs=output)
|
| 124 |
|