LeroyDyer commited on
Commit
98e3b9d
1 Parent(s): 79d7dec

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer
3
+ import torch
4
+ import os
5
+
6
+
7
+ def load_model(model_name):
8
+ return pipeline("text-generation", model=model_name, device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=True, token=os.environ["token"])
9
+
10
+ def generate(
11
+ model_name,
12
+ user_input,
13
+ temperature=0.4,
14
+ top_p=0.95,
15
+ top_k=50,
16
+ max_new_tokens=256,
17
+ ):
18
+ pipe = load_model(model_name)
19
+
20
+ # Set tokenize correctly. Otherwise ticking the box breaks it.
21
+ if model_name == "M4-ai/tau-1.8B":
22
+ prompt = user_input
23
+ else:
24
+ prompt = f"<|im_start|>user\n{user_input}<|im_end|>\n<|im_start|>assistant\n"
25
+ outputs = pipe(prompt, max_new_tokens=max_new_tokens, do_sample=True,
26
+ temperature=temperature, top_k=top_k, top_p=top_p, repetition_penalty=1.1)
27
+ return outputs[0]["generated_text"]
28
+
29
+ model_choices = ["LeroyDyer/Mixtral_Instruct","LeroyDyer/Mixtral_Chat","LeroyDyer/Mixtral_Chat_X","LeroyDyer/Mixtral_Chat_X_128k",
30
+ "LeroyDyer/Mixtral_AI_Instruct_X","LeroyDyer/Mixtral_AI_Thinker",
31
+ "LeroyDyer/Mixtral_AI_128k_BioMedical","Mixtral_BioMedical","LeroyDyer/Mixtral_Samantha",
32
+ "LeroyDyer/Mixtral_AI_Base_128k","LeroyDyer/Mixtral_Base","LeroyDyer/Mixtral_AI_1.0",
33
+ "LeroyDyer/Mixtral_AI_Vision_128K","LeroyDyer/Mixtral_AI_Base","LeroyDyer/Mixtral_AI_Medic_Base",
34
+ "LeroyDyer/Mixtral_AI_Vision_128K_X","LeroyDyer/Mixtral_AI_Vision_V1_128",
35
+ "LeroyDyer/Mixtral_AI_Cyber", "LeroyDyer/Mixtral_AI_Cyber_1.0","LeroyDyer/Mixtral_AI_Cyber_2.0",
36
+ ]
37
+ # What at the best options?
38
+ g = gr.Interface(
39
+ fn=generate,
40
+ inputs=[
41
+ gr.components.Dropdown(choices=model_choices, label="Model", value=model_choices[0], interactive=True),
42
+ gr.components.Textbox(lines=2, label="Prompt", value="Write me a Python program that calculates the factorial of a given number."),
43
+ gr.components.Slider(minimum=0, maximum=1, value=0.4, label="Temperature"),
44
+ gr.components.Slider(minimum=0, maximum=1, value=0.95, label="Top p"),
45
+ gr.components.Slider(minimum=0, maximum=100, step=1, value=50, label="Top k"),
46
+ gr.components.Slider(minimum=1, maximum=2048, step=1, value=1024, label="Max tokens"),
47
+ ],
48
+ outputs=[gr.Textbox(lines=10, label="Output")],
49
+ title="SpydazWeb AI (LeroyDyer) Language Models",
50
+ description="Each has thier own personality's ",
51
+ concurrency_limit=1
52
+ )
53
+
54
+ g.launch(max_threads=4)