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