KingNish commited on
Commit
0897689
1 Parent(s): c127950

modified: app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -3
app.py CHANGED
@@ -1,7 +1,38 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
 
 
 
4
 
5
+ def client_fn(model):
6
+ if "Mixtral" in model:
7
+ return InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
8
+ elif "Llama" in model:
9
+ return InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
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("microsoft/Phi-3-mini-4k-instruct")
16
+
17
+ system_instructions1 = "[SYSTEM] Answer as Real Jarvis JARVIS, Made by 'Tony Stark', Keep conversation very short, clear, friendly and concise. The text provided is a request for a specific type of response from you, the virtual assistant. The request asks you to provide friendly responses as if You are the character Jarvis, made by 'Tony Stark.' The expectation is that I will avoid introductions and start answering the query directly, Only answer the question asked by user, Do not say unnecessary things.[USER]"
18
+
19
+ def models(text, model="Mixtral 8x7B"):
20
+
21
+ client = client_fn(model)
22
+
23
+ generate_kwargs = dict(
24
+ max_new_tokens=300,
25
+ )
26
+
27
+ formatted_prompt = system_instructions1 + text + "[JARVIS]"
28
+ stream = client.text_generation(
29
+ formatted_prompt, **generate_kwargs, stream=True, details=False, return_full_text=False)
30
+ output = ""
31
+ for response in stream:
32
+ if not response.token.text == "</s>":
33
+ output += response.token.text
34
+
35
+ return output
36
+
37
+ demo = gr.Interface(fn=models, inputs=["text", gr.Dropdown([ 'Mixtral 8x7B','Llama 3 8B','Mistral 7B v0.3','Phi 3 mini', ], value="Mistral 7B v0.3", label="Select Model") ], outputs="text", live=True)
38
  demo.launch()