Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -59,19 +59,58 @@ agent = CodeAgent(
|
|
59 |
verbosity_level=1
|
60 |
)
|
61 |
|
62 |
-
#
|
63 |
-
|
64 |
-
###
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
#### Example Queries:
|
70 |
-
- "What is the current exchange rate for USD to JPY?"
|
71 |
-
- "Get the EUR to GBP rate."
|
72 |
-
- "What is the current time in America/New_York?"
|
73 |
-
- "Get the time in Asia/Tokyo."
|
74 |
"""
|
75 |
|
76 |
-
#
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
verbosity_level=1
|
60 |
)
|
61 |
|
62 |
+
# Define example usage instructions
|
63 |
+
example_usage = """
|
64 |
+
### Example Usage
|
65 |
+
1. **Currency Rate**: Ask for the exchange rate of a currency pair.
|
66 |
+
- Example: "What is the current exchange rate for USD to JPY?"
|
67 |
+
- Example: "Get the EUR to GBP rate.
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
"""
|
69 |
|
70 |
+
# Extend the GradioUI class to include the example usage
|
71 |
+
class CustomGradioUI(GradioUI):
|
72 |
+
def __init__(self, agent, description: str = "", **kwargs):
|
73 |
+
super().__init__(agent, **kwargs)
|
74 |
+
self.description = description
|
75 |
+
|
76 |
+
def launch(self, **kwargs):
|
77 |
+
import gradio as gr
|
78 |
+
|
79 |
+
with gr.Blocks(fill_height=True) as demo:
|
80 |
+
# Add the description as a Markdown component
|
81 |
+
if self.description:
|
82 |
+
gr.Markdown(self.description)
|
83 |
+
|
84 |
+
# Add the existing chatbot and input components
|
85 |
+
stored_messages = gr.State([])
|
86 |
+
file_uploads_log = gr.State([])
|
87 |
+
chatbot = gr.Chatbot(
|
88 |
+
label="Agent",
|
89 |
+
type="messages",
|
90 |
+
avatar_images=(
|
91 |
+
None,
|
92 |
+
"https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/communication/Alfred.png",
|
93 |
+
),
|
94 |
+
resizeable=True,
|
95 |
+
scale=1,
|
96 |
+
)
|
97 |
+
# If an upload folder is provided, enable the upload feature
|
98 |
+
if self.file_upload_folder is not None:
|
99 |
+
upload_file = gr.File(label="Upload a file")
|
100 |
+
upload_status = gr.Textbox(label="Upload Status", interactive=False, visible=False)
|
101 |
+
upload_file.change(
|
102 |
+
self.upload_file,
|
103 |
+
[upload_file, file_uploads_log],
|
104 |
+
[upload_status, file_uploads_log],
|
105 |
+
)
|
106 |
+
text_input = gr.Textbox(lines=1, label="Chat Message")
|
107 |
+
text_input.submit(
|
108 |
+
self.log_user_message,
|
109 |
+
[text_input, file_uploads_log],
|
110 |
+
[stored_messages, text_input],
|
111 |
+
).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])
|
112 |
+
|
113 |
+
demo.launch(debug=True, share=True, **kwargs)
|
114 |
+
|
115 |
+
# Launch the Gradio UI with the example usage
|
116 |
+
CustomGradioUI(agent, description=example_usage).launch()
|