yetessam commited on
Commit
0edee28
·
verified ·
1 Parent(s): 2392edf

Update ContentGradio.py

Browse files
Files changed (1) hide show
  1. ContentGradio.py +66 -67
ContentGradio.py CHANGED
@@ -1,8 +1,6 @@
1
  import gradio as gr
2
  import os
3
 
4
-
5
-
6
  # Function for Main content (takes user input and returns a response)
7
  def process_input(user_input):
8
  return f"You entered: {user_input}"
@@ -27,74 +25,75 @@ def get_example():
27
 
28
  return examples
29
 
30
- # Create the header section
31
- def create_header():
32
-
33
- agent_header = """
34
- #Content Agent
35
- """
36
- with gr.Row():
37
- gr.Markdown("<div id='header'>" + agent_header + "</div>")
38
-
39
- # Create the user guidance section
40
- def create_user_guidance():
41
-
42
- guidance = """
43
- Please enter text below to get started. The AI Agent will try to determine whether the language is polite and uses the following classification:
44
- - `polite`
45
- - `somewhat polite`
46
- - `neutral`
47
- - `impolite`
48
-
49
- App is running `deepseek-ai/DeepSeek-R1-Distill-Qwen-32B` text generation model.
50
- Uses Intel's Polite Guard NLP library.
51
- Compute is GCP · Nvidia L4 · 4x GPUs · 96 GB
52
- """
53
- with gr.Row():
54
- gr.Markdown("<div id='user-guidance'>" + guidance+ "</div>")
55
-
56
- # Create the main content section
57
- def create_main():
58
- with gr.Row():
59
- with gr.Column():
60
- user_input = gr.Textbox(label="Your Input", placeholder="Enter something here...")
61
- submit_button = gr.Button("Submit")
62
- output = gr.Textbox(label="Content feedback", interactive=False, lines=10, max_lines=20 )
63
-
64
- # Define the function to be called when the button is clicked or Enter is pressed
65
- submit_button.click(process_input, inputs=user_input, outputs=output)
66
- user_input.submit(process_input, inputs=user_input, outputs=output)
67
-
68
- return user_input, output # Return both input and output components
69
-
70
- # Create the examples section
71
- def create_examples(user_input):
72
- # Fetch examples by calling get_example() here
73
- examples = get_example()
74
- example_radio = gr.Radio(choices=examples, label="Try one of these examples:")
75
 
76
- # When an example is selected, populate the input field
77
- example_radio.change(fn=lambda example: example, inputs=example_radio, outputs=user_input)
78
-
79
- # Create the footer section
80
- def create_footer():
81
- with gr.Row():
82
- gr.Markdown("<div id='footer'>Thanks for trying it out!</div>")
 
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
- # Main function to bring all sections together
86
- def ContentAgentUI():
87
- # Set the path to the external CSS file
88
- css_path = os.path.join(os.getcwd(), "ui", "styles.css")
89
-
90
- with gr.Blocks(css=css_path) as ca_gui:
91
- create_header() # Create the header
92
- create_user_guidance() # Create user guidance section
93
- user_input, output = create_main() # Create the main section (returns the input/output components)
94
- create_examples(user_input) # Create the examples section
95
- create_footer() # Create the footer section
96
 
97
- # Launch the Gradio interface
98
- ca_gui.launch()
99
 
 
 
 
100
 
 
1
  import gradio as gr
2
  import os
3
 
 
 
4
  # Function for Main content (takes user input and returns a response)
5
  def process_input(user_input):
6
  return f"You entered: {user_input}"
 
25
 
26
  return examples
27
 
28
+ class ContentAgentUI:
29
+ def __init__(self):
30
+ # Set the path to the external CSS file
31
+ css_path = os.path.join(os.getcwd(), "ui", "styles.css")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ self.ca_gui = gr.Blocks(css=css_path)
34
+ self.sections = [
35
+ self.create_header,
36
+ self.create_user_guidance,
37
+ self.create_main,
38
+ self.create_examples,
39
+ self.create_footer,
40
+ ]
41
 
42
+ for section in self.sections:
43
+ section()
44
+
45
+ self.launch()
46
+
47
+ def create_header(self):
48
+ agent_header = """
49
+ #Content Agent
50
+ """
51
+ with self.ca_gui:
52
+ gr.Markdown("<div id='header'>" + agent_header + "</div>")
53
+
54
+ def create_user_guidance(self):
55
+ guidance = """
56
+ Please enter text below to get started. The AI Agent will try to determine whether the language is polite and uses the following classification:
57
+ - `polite`
58
+ - `somewhat polite`
59
+ - `neutral`
60
+ - `impolite`
61
+ App is running `deepseek-ai/DeepSeek-R1-Distill-Qwen-32B` text generation model.
62
+ Uses Intel's Polite Guard NLP library.
63
+ Compute is GCP · Nvidia L4 · 4x GPUs · 96 GB
64
+ """
65
+ with self.ca_gui:
66
+ gr.Markdown("<div id='user-guidance'>" + guidance + "</div>")
67
+
68
+ def create_main(self):
69
+ with self.ca_gui:
70
+ with gr.Row():
71
+ with gr.Column():
72
+ self.user_input = gr.Textbox(label="Your Input", placeholder="Enter something here...")
73
+ self.submit_button = gr.Button("Submit")
74
+ self.output = gr.Textbox(label="Content feedback", interactive=False, lines=10, max_lines=20 )
75
+
76
+ # Define the function to be called when the button is clicked or Enter is pressed
77
+ self.submit_button.click(process_input, inputs=self.user_input, outputs=self.output)
78
+ self.user_input.submit(process_input, inputs=self.user_input, outputs=self.output)
79
+
80
+ def create_examples(self):
81
+ # Fetch examples by calling get_example() here
82
+ examples = get_example()
83
+ example_radio = gr.Radio(choices=examples, label="Try one of these examples:")
84
+
85
+ # When an example is selected, populate the input field
86
+ with self.ca_gui:
87
+ example_radio.change(fn=lambda example: example, inputs=example_radio, outputs=self.user_input)
88
 
89
+ def create_footer(self):
90
+ with self.ca_gui:
91
+ gr.Markdown("<div id='footer'>Thanks for trying it out!</div>")
 
 
 
 
 
 
 
 
92
 
93
+ def launch(self):
94
+ self.ca_gui.launch()
95
 
96
+ def pass_through_agent(self, agent):
97
+ # Code to pass through the agent
98
+ pass
99