Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,10 +8,14 @@ import gradio as gr
|
|
8 |
|
9 |
def run_test(input_text):
|
10 |
if not input_text:
|
11 |
-
return "
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# TODO: Add model selection in the future
|
17 |
# Change mode name
|
@@ -63,6 +67,9 @@ css = """
|
|
63 |
border-radius: 8px;
|
64 |
padding: 12px;
|
65 |
border: 2px solid #d1d1d1;
|
|
|
|
|
|
|
66 |
}
|
67 |
|
68 |
/* Set button widths to match the Select Model width */
|
@@ -107,6 +114,28 @@ css = """
|
|
107 |
margin-bottom: 20px;
|
108 |
color: #ff5722;
|
109 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
"""
|
111 |
|
112 |
# Gradio App
|
@@ -135,15 +164,16 @@ with gr.Blocks(css=css) as app:
|
|
135 |
placeholder="Enter Text Here",
|
136 |
lines=8,
|
137 |
elem_classes=["input-text"], # Applying the CSS class
|
138 |
-
value="
|
139 |
)
|
140 |
output = gr.Textbox(
|
141 |
label="Inference Result",
|
142 |
placeholder="Made by Human or AI",
|
143 |
elem_id="output-text",
|
144 |
-
lines=
|
145 |
-
|
146 |
)
|
|
|
147 |
with gr.Row():
|
148 |
# TODO: Add model selection in the future
|
149 |
# model_name = gr.Dropdown(
|
@@ -161,7 +191,7 @@ with gr.Blocks(css=css) as app:
|
|
161 |
)
|
162 |
clear_button = gr.Button("Clear", variant="secondary", elem_classes=["button"])
|
163 |
|
164 |
-
submit_button.click(run_test, inputs=[input_text], outputs=output)
|
165 |
clear_button.click(lambda: ("", ""), inputs=[], outputs=[input_text, output])
|
166 |
|
167 |
with gr.Accordion("Disclaimer", open=True, elem_classes=["accordion"]):
|
|
|
8 |
|
9 |
def run_test(input_text):
|
10 |
if not input_text:
|
11 |
+
return [("Please enter text to analyze.", "error")]
|
12 |
+
result = relative_tester.test(input_text.strip())
|
13 |
+
if "Human" in result:
|
14 |
+
return [(result, "Human")]
|
15 |
+
elif "AI" in result:
|
16 |
+
return [(result, "AI")]
|
17 |
+
else:
|
18 |
+
return [(result, "Please enter a longer text")]
|
19 |
|
20 |
# TODO: Add model selection in the future
|
21 |
# Change mode name
|
|
|
67 |
border-radius: 8px;
|
68 |
padding: 12px;
|
69 |
border: 2px solid #d1d1d1;
|
70 |
+
text-align: center;
|
71 |
+
font-size: 1.2em;
|
72 |
+
font-weight: bold;
|
73 |
}
|
74 |
|
75 |
/* Set button widths to match the Select Model width */
|
|
|
114 |
margin-bottom: 20px;
|
115 |
color: #ff5722;
|
116 |
}
|
117 |
+
|
118 |
+
/* Green for Human text */
|
119 |
+
.highlighted-human {
|
120 |
+
background-color: #d4edda;
|
121 |
+
color: #155724;
|
122 |
+
border: 2px solid #28a745;
|
123 |
+
}
|
124 |
+
|
125 |
+
/* Red for AI text */
|
126 |
+
.highlighted-ai {
|
127 |
+
background-color: #f8d7da;
|
128 |
+
color: #721c24;
|
129 |
+
border: 2px solid #dc3545;
|
130 |
+
}
|
131 |
+
|
132 |
+
/* Yellow for errors */
|
133 |
+
.highlighted-error {
|
134 |
+
background-color: #fff3cd;
|
135 |
+
color: #856404;
|
136 |
+
border: 2px solid #ffc107;
|
137 |
+
}
|
138 |
+
|
139 |
"""
|
140 |
|
141 |
# Gradio App
|
|
|
164 |
placeholder="Enter Text Here",
|
165 |
lines=8,
|
166 |
elem_classes=["input-text"], # Applying the CSS class
|
167 |
+
value="Hugging Face is a company and community that has become one of the leading platforms in the field of natural language processing (NLP). It is best known for developing and maintaining the Transformers library, which simplifies the use of state-of-the-art machine learning models for tasks such as text classification, language generation, translation, and more."
|
168 |
)
|
169 |
output = gr.Textbox(
|
170 |
label="Inference Result",
|
171 |
placeholder="Made by Human or AI",
|
172 |
elem_id="output-text",
|
173 |
+
lines=2, # Keep it compact
|
174 |
+
interactive=False, # Make it read-only
|
175 |
)
|
176 |
+
|
177 |
with gr.Row():
|
178 |
# TODO: Add model selection in the future
|
179 |
# model_name = gr.Dropdown(
|
|
|
191 |
)
|
192 |
clear_button = gr.Button("Clear", variant="secondary", elem_classes=["button"])
|
193 |
|
194 |
+
submit_button.click(run_test, inputs=[input_text], outputs=[output])
|
195 |
clear_button.click(lambda: ("", ""), inputs=[], outputs=[input_text, output])
|
196 |
|
197 |
with gr.Accordion("Disclaimer", open=True, elem_classes=["accordion"]):
|