people_mate / test /new.py
zeyadahmedd's picture
Upload 3 files
058640f
raw
history blame
No virus
2.02 kB
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 = "<<SYS>>\n", "\n<</SYS>>\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