liamebs commited on
Commit
78e7cb0
1 Parent(s): 1538754

Send details for first run

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