NithyasriVllB commited on
Commit
ce748e4
·
verified ·
1 Parent(s): 2ae38a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -57
app.py CHANGED
@@ -1,57 +1,57 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- # Function to return the appropriate client based on the model selected
5
- def client_fn(model):
6
- model_map = {
7
- "Nous Hermes Mixtral 8x7B DPO": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
8
- "StarChat2 15b": "HuggingFaceH4/starchat2-15b-v0.1",
9
- "Mistral 7B v0.3": "mistralai/Mistral-7B-Instruct-v0.3",
10
- "Phi 3 mini": "microsoft/Phi-3-mini-4k-instruct",
11
- "Mixtral 8x7B": "mistralai/Mixtral-8x7B-Instruct-v0.1"
12
- }
13
- return InferenceClient(model_map.get(model, "mistralai/Mixtral-8x7B-Instruct-v0.1"))
14
-
15
- system_instructions = ("[SYSTEM] You are a chat bot named 'H go'."
16
- "Your task is to Answer the question."
17
- "Keep conversation very short, clear and concise."
18
- "Respond naturally and concisely to the user's queries. "
19
- "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."
20
- "Begin with a greeting if the user initiates the conversation. "
21
- "Here is the user's query:[QUESTION] ")
22
-
23
- # Function to generate model responses
24
- def models(text, model="Mixtral 8x7B"):
25
- client = client_fn(model)
26
- generate_kwargs = {
27
- "max_new_tokens": 100,
28
- "do_sample": True,
29
- }
30
-
31
- formatted_prompt = f"{system_instructions} {text} [ANSWER]"
32
- stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
33
-
34
- output = ""
35
- for response in stream:
36
- output += response.token.text
37
- if output.endswith("</s>"):
38
- output = output[:-4]
39
- return output
40
-
41
- # Gradio interface description and configuration
42
- description = """# H GO
43
- ### Inspired from Google Go"""
44
-
45
- with gr.Blocks() as demo:
46
- gr.Markdown(description)
47
-
48
- text_input = gr.Textbox(label="Enter your message here:")
49
- dropdown = gr.Dropdown(['Mixtral 8x7B', 'Nous Hermes Mixtral 8x7B DPO', 'StarChat2 15b', 'Mistral 7B v0.3', 'Phi 3 mini'], value="Mistral 7B v0.3", label="Select Model")
50
- submit_btn = gr.Button("Send")
51
- output_text = gr.Textbox(label="Response")
52
-
53
- submit_btn.click(fn=models, inputs=[text_input, dropdown], outputs=output_text)
54
-
55
- # Queue and launch configuration for Gradio
56
- demo.queue(max_size=300000)
57
- demo.launch()
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ # Function to return the appropriate client based on the model selected
5
+ def client_fn(model):
6
+ model_map = {
7
+ "Nous Hermes Mixtral 8x7B DPO": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
8
+ "StarChat2 15b": "HuggingFaceH4/starchat2-15b-v0.1",
9
+ "Mistral 7B v0.3": "mistralai/Mistral-7B-Instruct-v0.3",
10
+ "Phi 3 mini": "microsoft/Phi-3-mini-4k-instruct",
11
+ "Mixtral 8x7B": "mistralai/Mixtral-8x7B-Instruct-v0.1"
12
+ }
13
+ return InferenceClient(model_map.get(model, "mistralai/Mixtral-8x7B-Instruct-v0.1"))
14
+
15
+ system_instructions = ("[SYSTEM] You are a chat bot named 'NITHIYASRI'S CHATBOT'."
16
+ "Your task is to Answer the question."
17
+ "Keep conversation very short, clear and concise."
18
+ "Respond naturally and concisely to the user's queries. "
19
+ "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."
20
+ "Begin with a greeting if the user initiates the conversation. "
21
+ "Here is the user's query:[QUESTION] ")
22
+
23
+ # Function to generate model responses
24
+ def models(text, model="Mixtral 8x7B"):
25
+ client = client_fn(model)
26
+ generate_kwargs = {
27
+ "max_new_tokens": 100,
28
+ "do_sample": True,
29
+ }
30
+
31
+ formatted_prompt = f"{system_instructions} {text} [ANSWER]"
32
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
33
+
34
+ output = ""
35
+ for response in stream:
36
+ output += response.token.text
37
+ if output.endswith("</s>"):
38
+ output = output[:-4]
39
+ return output
40
+
41
+ # Gradio interface description and configuration
42
+ description = """# H GO
43
+ ### Inspired from Google Go"""
44
+
45
+ with gr.Blocks() as demo:
46
+ gr.Markdown(description)
47
+
48
+ text_input = gr.Textbox(label="Enter your message here:")
49
+ dropdown = gr.Dropdown(['Mixtral 8x7B', 'Nous Hermes Mixtral 8x7B DPO', 'StarChat2 15b', 'Mistral 7B v0.3', 'Phi 3 mini'], value="Mistral 7B v0.3", label="Select Model")
50
+ submit_btn = gr.Button("Send")
51
+ output_text = gr.Textbox(label="Response")
52
+
53
+ submit_btn.click(fn=models, inputs=[text_input, dropdown], outputs=output_text)
54
+
55
+ # Queue and launch configuration for Gradio
56
+ demo.queue(max_size=300000)
57
+ demo.launch()