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

Update demo.py

Browse files
Files changed (1) hide show
  1. demo.py +60 -44
demo.py CHANGED
@@ -1,72 +1,88 @@
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,11 +107,11 @@ with gr.Blocks(css=css) as app:
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,13 +130,13 @@ with gr.Blocks(css=css) as app:
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,4 +148,4 @@ with gr.Blocks(css=css) as app:
132
  ```
133
  """)
134
 
135
- app.launch()
 
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
  }
61
 
62
  /* Set button widths to match the Select Model width */
63
  .button {
64
+ width: 250px; /* Same as the select box width */
65
+ height: 100px; /* Button height */
66
  }
67
 
68
  /* Set height for the Select Model dropdown */
69
  .select {
70
+ height: 100px; /* Set height to 100px */
71
  }
72
 
73
  /* Accordion Styling */
74
  .accordion {
75
+ width: 100%; /* Set the width of the accordion to match the parent */
76
+ max-height: 200px; /* Set a max-height for accordion */
77
+ overflow-y: auto; /* Allow scrolling if the content exceeds max height */
78
+ margin-bottom: 10px; /* Add space below accordion */
79
+ box-sizing: border-box; /* Ensure padding is included in width/height */
80
+ }
81
+
82
+ /* Accordion content max-height */
83
+ .accordion-content {
84
+ max-height: 200px; /* Limit the height of the content */
85
+ overflow-y: auto; /* Add a scrollbar if content overflows */
86
  }
87
  """
88
 
 
107
  lines=8,
108
  elem_classes=["input-text"], # Applying the CSS class
109
  )
 
110
  output = gr.Textbox(
111
  label="Inference Result",
112
  placeholder="Made by Human or AI",
113
  elem_id="output-text",
114
+ elem_classes=["output-text"],
115
  )
116
  with gr.Row():
117
  model_name = gr.Dropdown(
 
130
  submit_button.click(run_test_power, inputs=[model_name, input_text, input_text], outputs=output)
131
  clear_button.click(lambda: ("", ""), inputs=[], outputs=[input_text, output])
132
 
133
+ with gr.Accordion("Disclaimer", open=False, elem_classes=["accordion"]):
134
  gr.Markdown("""
135
  - **Disclaimer**: This tool is for demonstration purposes only. It is not a foolproof AI detector.
136
  - **Accuracy**: Results may vary based on input length and quality.
137
  """)
138
 
139
+ with gr.Accordion("Citations", open=False, elem_classes=["accordion"]):
140
  gr.Markdown("""
141
  ```
142
  @inproceedings{zhangs2024MMDMP,
 
148
  ```
149
  """)
150
 
151
+ app.launch()