import gradio as gr from gradio_client import Client, handle_file import os # Define your Hugging Face token (make sure to set it as an environment variable) HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using an environment variable # Initialize the Gradio Client for the specified API #client = Client("on1onmangoes/CNIHUB10724v10", hf_token=HF_TOKEN) client = Client("on1onmangoes/CNIHUB101324v10", hf_token=HF_TOKEN) # on1onmangoes/CNIHUB101324v10 # Here's how you can fix it: # Update the conversation history within the function. # Return the updated history along with any other required outputs. # Function to handle chat API call # Function to handle chat API call def stream_chat_with_rag( message: str, history: list, client_name: str, system_prompt: str, num_retrieved_docs: int, num_docs_final: int, temperature: float, max_new_tokens: int, top_p: float, top_k: int, penalty: float, ): # Use the parameters provided by the UI response = client.predict( message=message, client_name=client_name, system_prompt=system_prompt, num_retrieved_docs=num_retrieved_docs, num_docs_final=num_docs_final, temperature=temperature, max_new_tokens=max_new_tokens, top_p=top_p, top_k=top_k, penalty=penalty, api_name="/chat" ) # Update the conversation history history = history + [(message, response)] # Return the assistant's reply and the updated history return "", history # # Function to handle chat API call # def stream_chat_with_rag( # message: str, # history: list, # client_name: str, # system_prompt: str, # num_retrieved_docs: int, # num_docs_final: int, # temperature: float, # max_new_tokens: int, # top_p: float, # top_k: int, # penalty: float, # ): # # Use the parameters provided by the UI # response = client.predict( # message=message, # client_name=client_name, # system_prompt=system_prompt, # num_retrieved_docs=num_retrieved_docs, # num_docs_final=num_docs_final, # temperature=temperature, # max_new_tokens=max_new_tokens, # top_p=top_p, # top_k=top_k, # penalty=penalty, # api_name="/chat" # ) # # Return the assistant's reply # return response # Function to handle PDF processing API call def process_pdf(pdf_file): return client.predict( pdf_file=handle_file(pdf_file), client_name="rosariarossi", # Hardcoded client name api_name="/process_pdf2" )[1] # Return only the result string # Function to handle search API call def search_api(query): return client.predict(query=query, api_name="/search_with_confidence") # Function to handle RAG API call def rag_api(question): return client.predict(question=question, api_name="/answer_with_rag") # CSS for custom styling CSS = """ # chat-container { height: 100vh; } """ # Title for the application TITLE = "