awinml commited on
Commit
8df9fa7
·
verified ·
1 Parent(s): b66d001

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +64 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import urllib.request
3
+ import gradio as gr
4
+ from llama_cpp import Llama
5
+
6
+
7
+ def download_file(file_link, filename):
8
+ # Checks if the file already exists before downloading
9
+ if not os.path.isfile(filename):
10
+ urllib.request.urlretrieve(file_link, filename)
11
+ print("File downloaded successfully.")
12
+ else:
13
+ print("File already exists.")
14
+
15
+
16
+ # Dowloading GGML model from HuggingFace
17
+ ggml_model_path = "https://huggingface.co/TheBloke/Starling-LM-7B-alpha-GGUF/resolve/main/starling-lm-7b-alpha.Q4_K_S.gguf"
18
+ filename = "starling-lm-7b-alpha.Q4_K_S.gguf"
19
+
20
+ download_file(ggml_model_path, filename)
21
+
22
+
23
+ llm = Llama(model_path=filename, n_ctx=512, n_batch=126)
24
+
25
+ def create_prompt(text):
26
+ prompt = f"""GPT4 Correct User: {text}<|end_of_turn|>GPT4 Correct Assistant:"""
27
+ return prompt
28
+
29
+ def generate_text(prompt="Who is the CEO of Apple?"):
30
+ input_text = create_prompt(prompt)
31
+ output = llm(
32
+ input_text,
33
+ max_tokens=256,
34
+ temperature=0.1,
35
+ top_p=0.5,
36
+ echo=False,
37
+ stop=["#"],
38
+ )
39
+ output_text = output["choices"][0]["text"].strip()
40
+
41
+ # Remove Prompt Echo from Generated Text
42
+ cleaned_output_text = output_text.replace(prompt, "")
43
+ return cleaned_output_text
44
+
45
+
46
+ description = "Starling-7B GGUF"
47
+
48
+ examples = [
49
+ ["What is the capital of France?", "The capital of France is Paris."],
50
+ [
51
+ "Who wrote the novel 'Pride and Prejudice'?",
52
+ "The novel 'Pride and Prejudice' was written by Jane Austen.",
53
+ ],
54
+ ["What is the square root of 64?", "The square root of 64 is 8."],
55
+ ]
56
+
57
+ gradio_interface = gr.Interface(
58
+ fn=generate_text,
59
+ inputs="text",
60
+ outputs="text",
61
+ examples=examples,
62
+ title="Starling-7B GGUF",
63
+ )
64
+ gradio_interface.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ llama-cpp-python==0.2.33