from gradio_client import Client import time # prompt=""" # من هي سلمي؟ # """ # #who is salma # en_Pr=""" # # who is salma # # """ # context=["في سلمي.pdf:سلمي هي مهندسة","في سلمي.pdf:سلمي هي طالبة في كلية حاسبات و معلومات","في اركلياب.pdf:سلمي هي موضفة في قسم الذكاء الاصطناعي"] # en_Cont=['in salma_ahmed.pdf: salma is a computer developer', 'in salmaaaaa3333.pdf: salma is an employee in arkleap ', 'in salmaaaaa3333.pdf: salma works from 9 to 5 ', 'in italy_emploee.pdf: salma is a agent who works as a spy ', 'in zolompa7.pdf:'] old=time.time() system_prompt = """You are a helpful assistant, you will use the provided context to answer user questions. Read the given context before answering questions and think step by step. If you can not answer a user question based on the provided context, inform the user. Do not use any other information for answering user. Provide a detailed answer to the question.""" B_INST, E_INST = "[INST]", "[/INST]" B_SYS, E_SYS = "<>\n", "\n<>\n\n" SYSTEM_PROMPT = B_SYS + system_prompt + E_SYS instruction = """ Context: {context} User: {question}""" prompt_template = B_INST + SYSTEM_PROMPT + instruction + E_INST def connect_to_llama(query,context): client = Client("https://huggingface-projects-llama-2-13b-chat.hf.space/--replicas/5c42d8wx6/") result = client.predict( """ question:"{}" context:"{}" answer: """.format(query, context), # str in 'parameter_7' Textbox component prompt_template , # str in 'Optional system prompt' Textbox component 2048, # int | float (numeric value between 0 and 4096) in 'Max new tokens' Slider componentو 0.1, 0.05, 1, # int | float (numeric value between 0.0 and 1) in 'Top-p (nucleus sampling)' Slider component 1, # int | float (numeric value between 1.0 and 2.0) in 'Repetition penalty' Slider component api_name="/chat" ) # print(time.time() - old, "sec") return result