Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import hf_hub_download
|
3 |
+
from llama_cpp import Llama
|
4 |
+
|
5 |
+
# Download the GGUF model into the Space's cache
|
6 |
+
model_path = hf_hub_download(
|
7 |
+
repo_id="TheBloke/Llama-2-7B-Chat-GGUF",
|
8 |
+
filename="llama2-7b-chat.gguf"
|
9 |
+
)
|
10 |
+
llm = Llama(model_path=model_path)
|
11 |
+
|
12 |
+
def generate(prompt: str, temperature: float, max_tokens: int):
|
13 |
+
resp = llm(prompt, temperature=temperature, max_tokens=max_tokens)
|
14 |
+
return resp["choices"][0]["text"]
|
15 |
+
|
16 |
+
iface = gr.Interface(
|
17 |
+
fn=generate,
|
18 |
+
inputs=[
|
19 |
+
gr.Textbox(lines=4, label="Prompt"),
|
20 |
+
gr.Slider(0.0, 1.0, 0.1, label="Temperature", value=0.7),
|
21 |
+
gr.Slider(16, 512, 16, label="Max Tokens", value=128),
|
22 |
+
],
|
23 |
+
outputs="text",
|
24 |
+
title="Llama-2-7B-Chat (Q4_0 on CPU)"
|
25 |
+
)
|
26 |
+
|
27 |
+
if __name__ == "__main__":
|
28 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|