Spaces:
Sleeping
Sleeping
Update ContentGradio.py
Browse files- ContentGradio.py +28 -25
ContentGradio.py
CHANGED
|
@@ -1,29 +1,6 @@
|
|
| 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}"
|
| 7 |
-
|
| 8 |
-
# Function to generate predefined examples
|
| 9 |
-
def get_example():
|
| 10 |
-
# Define the path to the 'examples' directory
|
| 11 |
-
example_root = os.path.join(os.path.dirname(__file__), "examples")
|
| 12 |
-
|
| 13 |
-
# Get list of all example text file paths
|
| 14 |
-
example_files = [os.path.join(example_root, _) for _ in os.listdir(example_root) if _.endswith("txt")]
|
| 15 |
-
|
| 16 |
-
# Read the content of each file (assuming they're plain text files)
|
| 17 |
-
examples = []
|
| 18 |
-
|
| 19 |
-
for file_path in example_files:
|
| 20 |
-
example_content = ""
|
| 21 |
-
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
| 22 |
-
example_content = f.read()
|
| 23 |
-
|
| 24 |
-
examples.append(example_content) # Append the content to the list
|
| 25 |
-
|
| 26 |
-
return examples
|
| 27 |
|
| 28 |
class ContentAgentUI:
|
| 29 |
def __init__(self):
|
|
@@ -78,6 +55,27 @@ class ContentAgentUI:
|
|
| 78 |
self.submit_button.click(process_input, inputs=self.user_input, outputs=self.output)
|
| 79 |
self.user_input.submit(process_input, inputs=self.user_input, outputs=self.output)
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
def create_examples(self):
|
| 82 |
# Fetch examples by calling get_example() here
|
| 83 |
examples = get_example()
|
|
@@ -95,7 +93,12 @@ class ContentAgentUI:
|
|
| 95 |
gr.Markdown("<div id='footer'>Thanks for trying it out!</div>")
|
| 96 |
|
| 97 |
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
try:
|
| 100 |
# Pass the input to the agent
|
| 101 |
output = agent.get_response(input_text)
|
|
@@ -122,7 +125,7 @@ class ContentAgentUI:
|
|
| 122 |
|
| 123 |
# Update the output text box with the agent's response
|
| 124 |
self.submit_button.click(
|
| 125 |
-
fn=
|
| 126 |
inputs=self.user_input,
|
| 127 |
outputs=self.output
|
| 128 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
class ContentAgentUI:
|
| 6 |
def __init__(self):
|
|
|
|
| 55 |
self.submit_button.click(process_input, inputs=self.user_input, outputs=self.output)
|
| 56 |
self.user_input.submit(process_input, inputs=self.user_input, outputs=self.output)
|
| 57 |
|
| 58 |
+
|
| 59 |
+
# Function to generate predefined examples
|
| 60 |
+
def get_example():
|
| 61 |
+
# Define the path to the 'examples' directory
|
| 62 |
+
example_root = os.path.join(os.path.dirname(__file__), "examples")
|
| 63 |
+
|
| 64 |
+
# Get list of all example text file paths
|
| 65 |
+
example_files = [os.path.join(example_root, _) for _ in os.listdir(example_root) if _.endswith("txt")]
|
| 66 |
+
|
| 67 |
+
# Read the content of each file (assuming they're plain text files)
|
| 68 |
+
examples = []
|
| 69 |
+
|
| 70 |
+
for file_path in example_files:
|
| 71 |
+
example_content = ""
|
| 72 |
+
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
| 73 |
+
example_content = f.read()
|
| 74 |
+
|
| 75 |
+
examples.append(example_content) # Append the content to the list
|
| 76 |
+
|
| 77 |
+
return examples
|
| 78 |
+
|
| 79 |
def create_examples(self):
|
| 80 |
# Fetch examples by calling get_example() here
|
| 81 |
examples = get_example()
|
|
|
|
| 93 |
gr.Markdown("<div id='footer'>Thanks for trying it out!</div>")
|
| 94 |
|
| 95 |
|
| 96 |
+
|
| 97 |
+
# Function for Main content (takes user input and returns a response)
|
| 98 |
+
def process_input(input_text):
|
| 99 |
+
#return f"You entered: {user_input}"
|
| 100 |
+
|
| 101 |
+
#def get_agent_response(input_text):
|
| 102 |
try:
|
| 103 |
# Pass the input to the agent
|
| 104 |
output = agent.get_response(input_text)
|
|
|
|
| 125 |
|
| 126 |
# Update the output text box with the agent's response
|
| 127 |
self.submit_button.click(
|
| 128 |
+
fn=process_input,
|
| 129 |
inputs=self.user_input,
|
| 130 |
outputs=self.output
|
| 131 |
)
|