Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -63,12 +63,6 @@ with gr.Blocks(css=CSS) as demo:
|
|
63 |
chatbot=chatbot,
|
64 |
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|
65 |
additional_inputs=[
|
66 |
-
gr.Dropdown(
|
67 |
-
['rosariarossi', 'bianchifiordaliso', 'lorenzoverdi'],
|
68 |
-
value="rosariarossi",
|
69 |
-
label="Select Client",
|
70 |
-
render=False,
|
71 |
-
),
|
72 |
gr.Textbox(
|
73 |
value="You are an expert assistant",
|
74 |
label="System Prompt",
|
@@ -178,6 +172,186 @@ if __name__ == "__main__":
|
|
178 |
|
179 |
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
|
183 |
|
|
|
63 |
chatbot=chatbot,
|
64 |
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|
65 |
additional_inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
gr.Textbox(
|
67 |
value="You are an expert assistant",
|
68 |
label="System Prompt",
|
|
|
172 |
|
173 |
|
174 |
|
175 |
+
# import gradio as gr
|
176 |
+
# from gradio_client import Client, handle_file
|
177 |
+
# import os
|
178 |
+
|
179 |
+
# # Define your Hugging Face token (make sure to set it as an environment variable)
|
180 |
+
# HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using an environment variable
|
181 |
+
|
182 |
+
# # Initialize the Gradio Client for the specified API
|
183 |
+
# client = Client("on1onmangoes/CNIHUB10724v9", hf_token=HF_TOKEN)
|
184 |
+
|
185 |
+
# # Function to handle chat API call
|
186 |
+
# def stream_chat_with_rag(message, system_prompt, num_retrieved_docs, num_docs_final, temperature, max_new_tokens, top_p, top_k, penalty):
|
187 |
+
# response = client.predict(
|
188 |
+
# message=message,
|
189 |
+
# client_name="rosariarossi", # Hardcoded client name
|
190 |
+
# system_prompt=system_prompt,
|
191 |
+
# num_retrieved_docs=num_retrieved_docs,
|
192 |
+
# num_docs_final=num_docs_final,
|
193 |
+
# temperature=temperature,
|
194 |
+
# max_new_tokens=max_new_tokens,
|
195 |
+
# top_p=top_p,
|
196 |
+
# top_k=top_k,
|
197 |
+
# penalty=penalty,
|
198 |
+
# api_name="/chat"
|
199 |
+
# )
|
200 |
+
# return response
|
201 |
+
|
202 |
+
# # Function to handle PDF processing API call
|
203 |
+
# def process_pdf(pdf_file):
|
204 |
+
# return client.predict(
|
205 |
+
# pdf_file=handle_file(pdf_file),
|
206 |
+
# client_name="rosariarossi", # Hardcoded client name
|
207 |
+
# api_name="/process_pdf2"
|
208 |
+
# )[1] # Return only the result string
|
209 |
+
|
210 |
+
# # Function to handle search API call
|
211 |
+
# def search_api(query):
|
212 |
+
# return client.predict(query=query, api_name="/search_with_confidence")
|
213 |
+
|
214 |
+
# # Function to handle RAG API call
|
215 |
+
# def rag_api(question):
|
216 |
+
# return client.predict(question=question, api_name="/answer_with_rag")
|
217 |
+
|
218 |
+
# # CSS for custom styling
|
219 |
+
# CSS = """
|
220 |
+
# # chat-container {
|
221 |
+
# height: 100vh;
|
222 |
+
# }
|
223 |
+
# """
|
224 |
+
|
225 |
+
# # Title for the application
|
226 |
+
# TITLE = "<h1 style='text-align:center;'>My Gradio Chat App</h1>"
|
227 |
+
|
228 |
+
# # Create the Gradio Blocks interface
|
229 |
+
# with gr.Blocks(css=CSS) as demo:
|
230 |
+
# gr.HTML(TITLE)
|
231 |
+
|
232 |
+
# with gr.Tab("Chat"):
|
233 |
+
# chatbot = gr.Chatbot() # Create a chatbot interface
|
234 |
+
|
235 |
+
# chat_interface = gr.ChatInterface(
|
236 |
+
# fn=stream_chat_with_rag,
|
237 |
+
# chatbot=chatbot,
|
238 |
+
# additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|
239 |
+
# additional_inputs=[
|
240 |
+
# gr.Dropdown(
|
241 |
+
# ['rosariarossi', 'bianchifiordaliso', 'lorenzoverdi'],
|
242 |
+
# value="rosariarossi",
|
243 |
+
# label="Select Client",
|
244 |
+
# render=False,
|
245 |
+
# ),
|
246 |
+
# gr.Textbox(
|
247 |
+
# value="You are an expert assistant",
|
248 |
+
# label="System Prompt",
|
249 |
+
# render=False,
|
250 |
+
# ),
|
251 |
+
# gr.Slider(
|
252 |
+
# minimum=1,
|
253 |
+
# maximum=10,
|
254 |
+
# step=1,
|
255 |
+
# value=10,
|
256 |
+
# label="Number of Initial Documents to Retrieve",
|
257 |
+
# render=False,
|
258 |
+
# ),
|
259 |
+
# gr.Slider(
|
260 |
+
# minimum=1,
|
261 |
+
# maximum=10,
|
262 |
+
# step=1,
|
263 |
+
# value=9,
|
264 |
+
# label="Number of Final Documents to Retrieve",
|
265 |
+
# render=False,
|
266 |
+
# ),
|
267 |
+
# gr.Slider(
|
268 |
+
# minimum=0.2,
|
269 |
+
# maximum=1,
|
270 |
+
# step=0.1,
|
271 |
+
# value=0,
|
272 |
+
# label="Temperature",
|
273 |
+
# render=False,
|
274 |
+
# ),
|
275 |
+
# gr.Slider(
|
276 |
+
# minimum=128,
|
277 |
+
# maximum=8192,
|
278 |
+
# step=1,
|
279 |
+
# value=1024,
|
280 |
+
# label="Max new tokens",
|
281 |
+
# render=False,
|
282 |
+
# ),
|
283 |
+
# gr.Slider(
|
284 |
+
# minimum=0.0,
|
285 |
+
# maximum=1.0,
|
286 |
+
# step=0.1,
|
287 |
+
# value=1.0,
|
288 |
+
# label="Top P",
|
289 |
+
# render=False,
|
290 |
+
# ),
|
291 |
+
# gr.Slider(
|
292 |
+
# minimum=1,
|
293 |
+
# maximum=20,
|
294 |
+
# step=1,
|
295 |
+
# value=20,
|
296 |
+
# label="Top K",
|
297 |
+
# render=False,
|
298 |
+
# ),
|
299 |
+
# gr.Slider(
|
300 |
+
# minimum=0.0,
|
301 |
+
# maximum=2.0,
|
302 |
+
# step=0.1,
|
303 |
+
# value=1.2,
|
304 |
+
# label="Repetition Penalty",
|
305 |
+
# render=False,
|
306 |
+
# ),
|
307 |
+
# ],
|
308 |
+
# )
|
309 |
+
|
310 |
+
# with gr.Tab("Process PDF"):
|
311 |
+
# pdf_input = gr.File(label="Upload PDF File")
|
312 |
+
# pdf_output = gr.Textbox(label="PDF Result", interactive=False)
|
313 |
+
|
314 |
+
# pdf_button = gr.Button("Process PDF")
|
315 |
+
# pdf_button.click(
|
316 |
+
# process_pdf,
|
317 |
+
# inputs=[pdf_input],
|
318 |
+
# outputs=pdf_output
|
319 |
+
# )
|
320 |
+
|
321 |
+
# with gr.Tab("Search"):
|
322 |
+
# query_input = gr.Textbox(label="Enter Search Query")
|
323 |
+
# search_output = gr.Textbox(label="Search Confidence Result", interactive=False)
|
324 |
+
|
325 |
+
# search_button = gr.Button("Search")
|
326 |
+
# search_button.click(
|
327 |
+
# search_api,
|
328 |
+
# inputs=query_input,
|
329 |
+
# outputs=search_output
|
330 |
+
# )
|
331 |
+
|
332 |
+
# with gr.Tab("Answer with RAG"):
|
333 |
+
# question_input = gr.Textbox(label="Enter Question for RAG")
|
334 |
+
# rag_output = gr.Textbox(label="RAG Answer Result", interactive=False)
|
335 |
+
|
336 |
+
# rag_button = gr.Button("Get Answer")
|
337 |
+
# rag_button.click(
|
338 |
+
# rag_api,
|
339 |
+
# inputs=question_input,
|
340 |
+
# outputs=rag_output
|
341 |
+
# )
|
342 |
+
|
343 |
+
# # Launch the app
|
344 |
+
# if __name__ == "__main__":
|
345 |
+
# demo.launch()
|
346 |
+
|
347 |
+
|
348 |
+
|
349 |
+
|
350 |
+
|
351 |
+
|
352 |
+
|
353 |
+
|
354 |
+
|
355 |
|
356 |
|
357 |
|