Chris4K commited on
Commit
d511ad0
·
verified ·
1 Parent(s): 2dd63bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -83
app.py CHANGED
@@ -107,89 +107,8 @@ with tabs[2]:
107
 
108
  # Tab 4: Developers
109
  with tabs[3]:
110
-
111
- # Developer-related content
112
- st.markdown('''
113
-
114
- # Hugging Face Agent and Tools Code Overview
115
-
116
- ## Overview
117
- The provided Python code implements an interactive Streamlit web application that allows users to interact with various tools through the Hugging Face API. The app integrates Hugging Face models and tools, enabling users to perform tasks such as text generation, sentiment analysis, and more.
118
-
119
- ## Imports
120
- The code imports several external libraries and modules, including:
121
- - `streamlit`: For building the web application.
122
- - `os`: For interacting with the operating system.
123
- - `base64`, `io`, `Image` (from `PIL`), `AudioSegment` (from `pydub`), `IPython`, `sf`: For handling images and audio.
124
- - `requests`: For making HTTP requests.
125
- - `pandas`: For working with DataFrames.
126
- - `matplotlib.figure`, `numpy`: For visualization.
127
- - `altair`, `Plot` (from `bokeh.models`), `px` (from `plotly.express`), `pdk` (from `pydeck`): For different charting libraries.
128
- - `time`: For handling time-related operations.
129
- - `transformers`: For loading tools and agents.
130
-
131
- ## ToolLoader Class
132
- The `ToolLoader` class is responsible for loading tools based on their names. It has methods to load tools from a list of tool names and handles potential errors during loading.
133
-
134
- ## CustomHfAgent Class
135
- The `CustomHfAgent` class extends the base `Agent` class from the `transformers` module. It is designed to interact with a remote inference API and includes methods for generating text based on a given prompt.
136
-
137
- ## Tool Loading and Customization
138
- - Tool names are defined in the `tool_names` list.
139
- - The `ToolLoader` instance (`tool_loader`) loads tools based on the provided names.
140
- - The `CustomHfAgent` instance (`agent`) is created with a specified URL endpoint, token, and additional tools.
141
- - New tools can be added by appending their names to the `tool_names` list.
142
-
143
- ## Streamlit App
144
- The Streamlit app is structured as follows:
145
- 1. Tool selection dropdown for choosing the inference URL.
146
- 2. An expander for displaying tool descriptions.
147
- 3. An expander for selecting tools.
148
- 4. Examples and instructions for the user.
149
- 5. A chat interface for user interactions.
150
- 6. Handling of user inputs, tool selection, and agent responses.
151
-
152
- ## Handling of Responses
153
- The code handles various types of responses from the agent, including images, audio, text, DataFrames, and charts. The responses are displayed in the Streamlit app based on their types.
154
-
155
- ## How to Run
156
- 1. Install required dependencies with `pip install -r requirements.txt`.
157
- 2. Run the app with `streamlit run <filename.py>`.
158
-
159
- ## Notes
160
- - The code emphasizes customization and extensibility, allowing developers to easily add new tools and interact with the Hugging Face API.
161
- - Ensure proper configuration, such as setting the Hugging Face token as an environment variable.
162
-
163
- ''')
164
-
165
-
166
- # Display logs in the frontend
167
- logs_expander = st.expander("Logs")
168
- with logs_expander:
169
- log_output = st.empty()
170
-
171
- # Custom logging handler to append log messages to the chat
172
- class ChatHandler(logging.Handler):
173
- def __init__(self):
174
- super().__init__()
175
-
176
- def emit(self, record):
177
- log_message = self.format(record)
178
- with st.chat_message("ai"):
179
- st.markdown(f"Log: {log_message}")
180
-
181
- # Add the custom handler to the transformers_logger
182
- chat_handler = ChatHandler()
183
- transformers_logger.addHandler(chat_handler)
184
-
185
- # Function to update logs in the frontend
186
- def update_logs():
187
- log_output.code("") # Clear previous logs
188
- # Do nothing here since logs are appended to the chat
189
-
190
- # Update logs when the button is clicked
191
- if st.button("Update Logs"):
192
- update_logs()
193
 
194
 
195
  # Chat code (user input, agent responses, etc.)
 
107
 
108
  # Tab 4: Developers
109
  with tabs[3]:
110
+ app_dev_desc()
111
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
 
114
  # Chat code (user input, agent responses, etc.)