Spaces:
Sleeping
Sleeping
Update ContentGradio.py
Browse files- ContentGradio.py +21 -18
ContentGradio.py
CHANGED
@@ -1,19 +1,20 @@
|
|
1 |
-
|
2 |
-
import
|
|
|
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}"
|
7 |
|
8 |
# Function to generate predefined examples
|
9 |
-
def get_example(
|
10 |
-
|
11 |
example_root = os.path.join(os.path.dirname(__file__), "examples")
|
12 |
-
|
|
|
13 |
example_files = [os.path.join(example_root, _) for _ in os.listdir(example_root) if _.endswith("txt")]
|
14 |
|
15 |
-
|
16 |
-
# Read the content of each file (assuming they're text-based PDFs or plain text files)
|
17 |
examples = []
|
18 |
|
19 |
for file_path in example_files:
|
@@ -21,12 +22,10 @@ def get_example(example):
|
|
21 |
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
22 |
example_content = f.read()
|
23 |
|
24 |
-
examples.append(example_content) #
|
25 |
|
26 |
-
|
27 |
return examples
|
28 |
|
29 |
-
|
30 |
# Create the header section
|
31 |
def create_header():
|
32 |
with gr.Row():
|
@@ -44,15 +43,16 @@ def create_main():
|
|
44 |
user_input = gr.Textbox(label="Your Input", placeholder="Enter something here...")
|
45 |
output = gr.Textbox(label="Output", interactive=False)
|
46 |
user_input.submit(process_input, inputs=user_input, outputs=output)
|
47 |
-
return output # Return
|
48 |
|
49 |
# Create the examples section
|
50 |
-
def create_examples(
|
51 |
-
|
52 |
-
examples = get_example
|
53 |
|
54 |
with gr.Row():
|
55 |
gr.Markdown("<div id='examples'>Try one of these examples:</div>")
|
|
|
56 |
example_radio = gr.Radio(choices=examples, label="Select an Example")
|
57 |
|
58 |
# When an example is selected, populate the input field
|
@@ -65,15 +65,18 @@ def create_footer():
|
|
65 |
|
66 |
# Main function to bring all sections together
|
67 |
def ContentAgentUI():
|
68 |
-
|
69 |
css_path = os.path.join(os.getcwd(), "ui", "styles.css")
|
|
|
70 |
with gr.Blocks(css=css_path) as ca_gui:
|
71 |
create_header() # Create the header
|
72 |
create_user_guidance() # Create user guidance section
|
73 |
-
output = create_main() # Create the main section (returns the output
|
74 |
-
create_examples(
|
75 |
create_footer() # Create the footer section
|
76 |
|
|
|
77 |
ca_gui.launch()
|
78 |
|
79 |
-
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
|
5 |
# Function for Main content (takes user input and returns a response)
|
6 |
def process_input(user_input):
|
7 |
return f"You entered: {user_input}"
|
8 |
|
9 |
# Function to generate predefined examples
|
10 |
+
def get_example():
|
11 |
+
# Define the path to the 'examples' directory
|
12 |
example_root = os.path.join(os.path.dirname(__file__), "examples")
|
13 |
+
|
14 |
+
# Get list of all example text file paths
|
15 |
example_files = [os.path.join(example_root, _) for _ in os.listdir(example_root) if _.endswith("txt")]
|
16 |
|
17 |
+
# Read the content of each file (assuming they're plain text files)
|
|
|
18 |
examples = []
|
19 |
|
20 |
for file_path in example_files:
|
|
|
22 |
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
23 |
example_content = f.read()
|
24 |
|
25 |
+
examples.append(example_content) # Append the content to the list
|
26 |
|
|
|
27 |
return examples
|
28 |
|
|
|
29 |
# Create the header section
|
30 |
def create_header():
|
31 |
with gr.Row():
|
|
|
43 |
user_input = gr.Textbox(label="Your Input", placeholder="Enter something here...")
|
44 |
output = gr.Textbox(label="Output", interactive=False)
|
45 |
user_input.submit(process_input, inputs=user_input, outputs=output)
|
46 |
+
return user_input, output # Return both input and output components
|
47 |
|
48 |
# Create the examples section
|
49 |
+
def create_examples(user_input):
|
50 |
+
# Fetch examples by calling get_example() here
|
51 |
+
examples = get_example()
|
52 |
|
53 |
with gr.Row():
|
54 |
gr.Markdown("<div id='examples'>Try one of these examples:</div>")
|
55 |
+
# Create a Radio component with the list of examples
|
56 |
example_radio = gr.Radio(choices=examples, label="Select an Example")
|
57 |
|
58 |
# When an example is selected, populate the input field
|
|
|
65 |
|
66 |
# Main function to bring all sections together
|
67 |
def ContentAgentUI():
|
68 |
+
# Set the path to the external CSS file
|
69 |
css_path = os.path.join(os.getcwd(), "ui", "styles.css")
|
70 |
+
|
71 |
with gr.Blocks(css=css_path) as ca_gui:
|
72 |
create_header() # Create the header
|
73 |
create_user_guidance() # Create user guidance section
|
74 |
+
user_input, output = create_main() # Create the main section (returns the input/output components)
|
75 |
+
create_examples(user_input) # Create the examples section
|
76 |
create_footer() # Create the footer section
|
77 |
|
78 |
+
# Launch the Gradio interface
|
79 |
ca_gui.launch()
|
80 |
|
81 |
+
# Run the app
|
82 |
+
ContentAgentUI()
|