jer233 commited on
Commit
721dda7
·
verified ·
1 Parent(s): 8570cc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -8
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 "Now that you've built a demo, you'll probably want to share it with others. Gradio demos can be shared in two ways: using a temporary share link or permanent hosting on Spaces."
12
- # return two_sample_tester.test(input_text.strip())
13
- # return relative_tester.test(input_text.strip())
14
- return f"Prediction: Human (Mocked for {input_text})"
 
 
 
 
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="Archetypes represent universal patterns that define certain events, objects, or people. In literature, they reflect common themes and ideas that resonate across cultures, helping people interpret and relate to stories. However, archetypes are not limited to literature; they also exist in everyday life and play a vital role in shaping how we perceive the world. Specifically, archetypes of people help us understand their character, actions, and motivations. In real life, we can identify certain types of individuals who share common traits shaped by both personal inclinations and their environments. For instance, a modern corporate leader like Elon Musk exemplifies the archetype of a hero or creator. His vision and courage to innovate make him a prime example of this archetype, as others often view him as someone driven by a desire to transform the world. These traits influence not only how he is perceived but also his actions and motivations. Recognizing archetypes in daily life allows for a deeper understanding of people and events. By identifying these characteristics, I can better grasp someone’s motivations and role, making their behavior more predictable. While real-life individuals may exhibit a blend of archetypal traits, the concept still helps me interpret their actions and personalities, which in turn informs how I interact with them. (This is a example from Chatgpt)"
139
  )
140
  output = gr.Textbox(
141
  label="Inference Result",
142
  placeholder="Made by Human or AI",
143
  elem_id="output-text",
144
- lines=8,
145
- elem_classes=["output-text"],
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"]):