KingNish commited on
Commit
6cbb926
1 Parent(s): 48dc1ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -33
app.py CHANGED
@@ -1,43 +1,28 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
4
 
5
- def client_fn(model):
6
- if "Nous" in model:
7
- return InferenceClient("NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO")
8
- elif "Star" in model:
9
- return InferenceClient("HuggingFaceH4/starchat2-15b-v0.1")
10
- elif "Mistral" in model:
11
- return InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
12
- elif "Phi" in model:
13
- return InferenceClient("microsoft/Phi-3-mini-4k-instruct")
14
- else:
15
- return InferenceClient("google/gemma-1.1-2b-it")
16
-
17
- 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]"
18
-
19
- def models(text, model="Mixtral 8x7B"):
20
-
21
- client = client_fn(model)
22
-
23
- generate_kwargs = dict(
24
- max_new_tokens=100,
25
- do_sample=True,
26
- )
27
 
28
- formatted_prompt = system_instructions1 + text + "[ANSWER]"
29
- stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
30
- output = ""
31
- for response in stream:
32
- output+=response.token.text
33
- if output.endswith("<|assistant|>"):
34
- output = output[:-13]
35
- elif output.endswith("</s>"):
36
- output = output[:-4]
37
- return output
 
 
 
38
 
39
  description="# Chat GO"
40
 
41
- 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)
42
  demo.queue(max_size=300000)
43
  demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ client = InferenceClient("google/gemma-1.1-2b-it")
5
 
6
+ 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]"
7
+
8
+ def models(message):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ 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}"})
11
+
12
+ response = ""
13
+
14
+ for message in client.chat_completion(
15
+ messages,
16
+ max_tokens=200,
17
+ stream=True
18
+ ):
19
+ token = message.choices[0].delta.content
20
+
21
+ response += token
22
+ yield response
23
 
24
  description="# Chat GO"
25
 
26
+ demo = gr.Interface(description=description,fn=models, inputs=["text"], outputs="text", live=True, batch=True, max_batch_size=10000)
27
  demo.queue(max_size=300000)
28
  demo.launch()