jer233 commited on
Commit
9b7ecd8
·
verified ·
1 Parent(s): 446220d

Update demo.py

Browse files
Files changed (1) hide show
  1. demo.py +44 -61
demo.py CHANGED
@@ -1,89 +1,72 @@
1
  import gradio as gr
2
- import spaces
3
-
4
-
5
- # TOKENIZER =
6
- # MINIMUM_TOKENS = 64
7
-
8
- # def count_tokens(text):
9
- # return len(TOKENIZER(text).input_ids)
10
-
11
 
12
  # Mock function for testing layout
13
  def run_test_power(model_name, real_text, generated_text, N=10):
14
  return f"Prediction: Human (Mocked for {model_name})"
15
 
 
 
 
 
 
 
 
16
 
 
 
 
 
 
17
 
18
- # Change mode name
19
- #def change_mode(mode):
20
- # if mode == "Faster Model":
21
- # .change_mode("t5-small")
22
- # elif mode == "Medium Model":
23
- # .change_mode("roberta-base-openai-detector")
24
- # elif mode == "Powerful Model":
25
- # .change_mode("falcon-rw-1b")
26
- # else:
27
- # gr.Error(f"Invaild mode selected.")
28
- # return mode
29
-
30
-
31
 
32
- css = """
33
- #header { text-align: center; font-size: 3em; margin-bottom: 20px; }
34
- #output-text { font-weight: bold; font-size: 1.2em; }
35
- .links {
36
- display: flex;
37
- justify-content: flex-end;
38
- gap: 10px;
39
- margin-right: 10px;
40
  align-items: center;
41
  }
 
42
  .separator {
43
  margin: 0 5px;
44
  color: black;
45
  }
46
 
47
- /* Adjusting layout for Input Text and Inference Result */
48
- .input-row {
49
- display: flex;
50
- width: 100%;
51
- }
52
-
53
  .input-text {
54
- flex: 3; /* 4 parts of the row */
55
- margin-right: 1px;
56
- }
57
-
58
- .output-text {
59
- flex: 1; /* 1 part of the row */
60
- text-align: center;
61
  }
62
 
63
  /* Set button widths to match the Select Model width */
64
  .button {
65
- width: 250px; /* Same as the select box width */
66
- height: 100px; /* Button height */
67
  }
68
 
69
  /* Set height for the Select Model dropdown */
70
  .select {
71
- height: 100px; /* Set height to 100px */
72
  }
73
 
74
  /* Accordion Styling */
75
  .accordion {
76
- width: 100%; /* Set the width of the accordion to match the parent */
77
- max-height: 200px; /* Set a max-height for accordion */
78
- overflow-y: auto; /* Allow scrolling if the content exceeds max height */
79
- margin-bottom: 10px; /* Add space below accordion */
80
- box-sizing: border-box; /* Ensure padding is included in width/height */
81
- }
82
-
83
- /* Accordion content max-height */
84
- .accordion-content {
85
- max-height: 200px; /* Limit the height of the content */
86
- overflow-y: auto; /* Add a scrollbar if content overflows */
87
  }
88
  """
89
 
@@ -108,11 +91,11 @@ with gr.Blocks(css=css) as app:
108
  lines=8,
109
  elem_classes=["input-text"], # Applying the CSS class
110
  )
 
111
  output = gr.Textbox(
112
  label="Inference Result",
113
  placeholder="Made by Human or AI",
114
  elem_id="output-text",
115
- elem_classes=["output-text"],
116
  )
117
  with gr.Row():
118
  model_name = gr.Dropdown(
@@ -131,13 +114,13 @@ with gr.Blocks(css=css) as app:
131
  submit_button.click(run_test_power, inputs=[model_name, input_text, input_text], outputs=output)
132
  clear_button.click(lambda: ("", ""), inputs=[], outputs=[input_text, output])
133
 
134
- with gr.Accordion("Disclaimer", open=False, elem_classes=["accordion"]):
135
  gr.Markdown("""
136
  - **Disclaimer**: This tool is for demonstration purposes only. It is not a foolproof AI detector.
137
  - **Accuracy**: Results may vary based on input length and quality.
138
  """)
139
 
140
- with gr.Accordion("Citations", open=False, elem_classes=["accordion"]):
141
  gr.Markdown("""
142
  ```
143
  @inproceedings{zhangs2024MMDMP,
@@ -149,4 +132,4 @@ with gr.Blocks(css=css) as app:
149
  ```
150
  """)
151
 
152
- app.launch()
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
2
 
3
  # Mock function for testing layout
4
  def run_test_power(model_name, real_text, generated_text, N=10):
5
  return f"Prediction: Human (Mocked for {model_name})"
6
 
7
+ # CSS to adjust layout for the text boxes and dropdown
8
+ css = """
9
+ #header {
10
+ text-align: center;
11
+ font-size: 3em;
12
+ margin-bottom: 20px;
13
+ }
14
 
15
+ #output-text {
16
+ font-weight: bold;
17
+ font-size: 1.2em;
18
+ text-align: center; /* Center the text inside the box */
19
+ }
20
 
21
+ /* Flex container for centering output-text */
22
+ .center-container {
23
+ display: flex;
24
+ flex-direction: column;
25
+ justify-content: center;
26
+ align-items: center;
27
+ height: 400px; /* Set a fixed height for the container */
28
+ margin-top: 20px; /* Add some space above the container */
29
+ margin-bottom: 20px; /* Add some space below the container */
30
+ }
 
 
 
31
 
32
+ .links {
33
+ display: flex;
34
+ justify-content: flex-end;
35
+ gap: 10px;
36
+ margin-right: 10px;
 
 
 
37
  align-items: center;
38
  }
39
+
40
  .separator {
41
  margin: 0 5px;
42
  color: black;
43
  }
44
 
45
+ /* Adjusting layout for Input Text */
 
 
 
 
 
46
  .input-text {
47
+ width: 100%;
48
+ height: 100px;
49
+ font-size: 1em;
 
 
 
 
50
  }
51
 
52
  /* Set button widths to match the Select Model width */
53
  .button {
54
+ width: 250px; /* Same as the select box width */
55
+ height: 100px; /* Button height */
56
  }
57
 
58
  /* Set height for the Select Model dropdown */
59
  .select {
60
+ height: 100px; /* Set height to 100px */
61
  }
62
 
63
  /* Accordion Styling */
64
  .accordion {
65
+ width: 100%; /* Set the width of the accordion to match the parent */
66
+ max-height: 200px; /* Set a max-height for accordion */
67
+ overflow-y: auto; /* Allow scrolling if the content exceeds max height */
68
+ margin-bottom: 10px; /* Add space below the accordion */
69
+ box-sizing: border-box; /* Ensure padding is included in width/height */
 
 
 
 
 
 
70
  }
71
  """
72
 
 
91
  lines=8,
92
  elem_classes=["input-text"], # Applying the CSS class
93
  )
94
+ with gr.Row(elem_classes=["center-container"]): # Parent container for centering
95
  output = gr.Textbox(
96
  label="Inference Result",
97
  placeholder="Made by Human or AI",
98
  elem_id="output-text",
 
99
  )
100
  with gr.Row():
101
  model_name = gr.Dropdown(
 
114
  submit_button.click(run_test_power, inputs=[model_name, input_text, input_text], outputs=output)
115
  clear_button.click(lambda: ("", ""), inputs=[], outputs=[input_text, output])
116
 
117
+ with gr.Accordion("Disclaimer", open=False):
118
  gr.Markdown("""
119
  - **Disclaimer**: This tool is for demonstration purposes only. It is not a foolproof AI detector.
120
  - **Accuracy**: Results may vary based on input length and quality.
121
  """)
122
 
123
+ with gr.Accordion("Citations", open=False):
124
  gr.Markdown("""
125
  ```
126
  @inproceedings{zhangs2024MMDMP,
 
132
  ```
133
  """)
134
 
135
+ app.launch()