Spaces:
Build error
Build error
Update app.py
Browse files123455678910111213141516171819678202122232425269282930313233343536371011121314151617181920212223242541262728import gradio as grfrom huggingface_hub import InferenceClient
client = InferenceClient("google/gemma-1.1-2b-it")
def client_fn(model): if "Nous" in model: return InferenceClient("NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO") elif "Star" in model: return InferenceClient("HuggingFaceH4/starchat2-15b-v0.1") elif "Mistral" in model: return InferenceClient("mistralai/Mistral-7B-Instruct-v0.3") elif "Phi" in model: return InferenceClient("microsoft/Phi-3-mini-4k-instruct") else: return InferenceClient("google/gemma-1.1-2b-it")
system_instructions1 = "[SYSTEM] Your task is to Answer the question. Keep conversation very short, clear and concise. The expectation is that you will avoid introductions and start answering the query directly, Only answer the question asked by user, Do not say unnecessary things.[QUESTION]"
def models(text, model="Mixtral 8x7B"): system_instructions = "[SYSTEM] Your task is to Answer the question. Keep conversation very short, clear and concise. The expectation is that you will avoid introductions and start answering the query directly, Only answer the question asked by user, Do not say unnecessary things.[QUESTION]"
def models(message): client = client_fn(model) generate_kwargs = dict( max_new_tokens=100, do_sample=True, ) formatted_prompt = system_instructions1 + text + "[ANSWER]" stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False) output = "" for response in stream: output+=response.token.text if output.endswith("<|assistant|>"): output = output[:-13] elif output.endswith("</s>"): output = output[:-4] return output messages.append({"role": "user", "content": f"[SYSTEM] You are REAL TIME QnA AI who answer question asked by uer in short and concise [USER] {message}"})
response = ""
for message in client.chat_completion( messages, max_tokens=200, stream=True ): token = message.choices[0].delta.content
response += token yield response
description="# Chat GO"
demo = gr.Interface(description=description,fn=models, inputs=["text", gr.Dropdown([ 'Mixtral 8x7B','Nous Hermes Mixtral 8x7B DPO','StarChat2 15b','Mistral 7B v0.3','Phi 3 mini', 'FASTEST' ], value="FASTEST", label="Select Model") ], outputs="text", live=True, batch=True, max_batch_size=10000)demo = gr.Interface(description=description,fn=models, inputs=["text"], outputs="text", live=True, batch=True, max_batch_size=10000)demo.queue(max_size=300000)demo.launch()app.py+18-33