Erik commited on
Commit
a99a049
·
verified ·
1 Parent(s): 2e41aa9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -0
app.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from llama_cpp import Llama
3
+ from huggingface_hub import hf_hub_download
4
+
5
+ # GGUF model filenames
6
+ MODELS = {
7
+ "DeepSeek Chat (7B Chat)": "deepseek-llm-7b-chat-Q4_K_M.gguf",
8
+ "LLaMA 2 7B Chat": "llama-2-7b-chat.Q4_K_M.gguf",
9
+ "Smol 7B Chat (GGUF)": "smol-7b-Q4_K_M.gguf",
10
+ "DeepSeek Coder (6.7B Instruct)": "deepseek-coder-6.7b-instruct-Q4_K_M.gguf",
11
+ # Tiny test model
12
+ "TinyLlama 1.1B Test": "tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf"
13
+ }
14
+
15
+ # Corresponding Hugging Face repo IDs
16
+ REPO_IDS = {
17
+ "DeepSeek Chat (7B Chat)": "TheBloke/deepseek-llm-7B-chat-GGUF",
18
+ "LLaMA 2 7B Chat": "TheBloke/Llama-2-7B-Chat-GGUF",
19
+ "Smol 7B Chat (GGUF)": "TheBloke/smol-7B-GGUF",
20
+ "DeepSeek Coder (6.7B Instruct)": "second-state/Deepseek-Coder-6.7B-Instruct-GGUF",
21
+ # Tiny test model repo
22
+ "TinyLlama 1.1B Test": "TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF"
23
+ }
24
+
25
+ # System prompts per model
26
+ SYSTEM_PROMPTS = {
27
+ "DeepSeek Chat (7B Chat)": "You are a helpful assistant for friendly conversation:",
28
+ "LLaMA 2 7B Chat": "You are a helpful general AI assistant:",
29
+ "Smol 7B Chat (GGUF)": "You are a friendly general chat assistant:",
30
+ "DeepSeek Coder (6.7B Instruct)": "You are an instruction-following assistant:",
31
+ "TinyLlama 1.1B Test": "You are a lightweight test chat assistant:"
32
+ }
33
+
34
+ loaded_models = {}
35
+
36
+ def load_model(choice):
37
+ if choice not in loaded_models:
38
+ # Download GGUF model file from Hugging Face Hub
39
+ model_path = hf_hub_download(repo_id=REPO_IDS[choice], filename=MODELS[choice])
40
+ loaded_models[choice] = Llama(model=model_path, n_ctx=2048)
41
+ return loaded_models[choice]
42
+
43
+ def generate_chat(model_choice, history):
44
+ llm = load_model(model_choice)
45
+ user_msg = history[-1][0]
46
+ prompt = f"{SYSTEM_PROMPTS.get(model_choice, '')}\n{user_msg}"
47
+ out = llm(prompt, max_tokens=150)["choices"][0]["text"]
48
+ history[-1] = (user_msg, out)
49
+ return history
50
+
51
+ # Quick preset helper
52
+ def preset_text(text):
53
+ return text
54
+
55
+ with gr.Blocks() as demo:
56
+ gr.Markdown("# Playground.Deeemoi — Multi-Model Chat + Quick Prompts")
57
+
58
+ selector = gr.Dropdown(list(MODELS.keys()), label="Choose Model")
59
+
60
+ with gr.Row():
61
+ explain_btn = gr.Button("Explain")
62
+ summarize_btn = gr.Button("Summarize")
63
+ translate_btn = gr.Button("Translate to Spanish")
64
+ code_help_btn = gr.Button("Code Help")
65
+
66
+ chat_ui = gr.ChatInterface(
67
+ fn=lambda history, model_choice=selector: generate_chat(model_choice, history),
68
+ title="Chat with Quantized GGUF Models"
69
+ )
70
+
71
+ explain_btn.click(lambda: preset_text("Explain this clearly:"), None, chat_ui)
72
+ summarize_btn.click(lambda: preset_text("Summarize this text:"), None, chat_ui)
73
+ translate_btn.click(lambda: preset_text("Translate to Spanish:"), None, chat_ui)
74
+ code_help_btn.click(lambda: preset_text("Help with this code snippet:"), None, chat_ui)
75
+
76
+ selector.change(lambda _: [], None, chat_ui)
77
+
78
+ demo.launch()