nicohrubec commited on
Commit
acd70bd
1 Parent(s): 4c7e10c

implement endpoint

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +50 -0
  3. requirements.txt +68 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .idea
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/CRD716/ggml-vicuna-1.1-quantized/resolve/main/ggml-vicuna-7b-1.1-q4_1.bin"
18
+ filename = "ggml-vicuna-7b-1.1-q4_1.bin"
19
+
20
+ download_file(ggml_model_path, filename)
21
+
22
+
23
+ llm = Llama(model_path=filename, n_ctx=512, n_batch=126)
24
+
25
+
26
+ def generate_text(prompt="Who is the CEO of Apple?"):
27
+ output = llm(
28
+ prompt,
29
+ max_tokens=256,
30
+ temperature=0.1,
31
+ top_p=0.5,
32
+ echo=False,
33
+ stop=["#"],
34
+ )
35
+ output_text = output["choices"][0]["text"].strip()
36
+
37
+ # Remove Prompt Echo from Generated Text
38
+ cleaned_output_text = output_text.replace(prompt, "")
39
+ return cleaned_output_text
40
+
41
+
42
+ description = "Vicuna-7B"
43
+
44
+ gradio_interface = gr.Interface(
45
+ fn=generate_text,
46
+ inputs="text",
47
+ outputs="text",
48
+ title="Vicuna-7B",
49
+ )
50
+ gradio_interface.launch()
requirements.txt ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ altair==5.2.0
3
+ annotated-types==0.6.0
4
+ anyio==3.7.1
5
+ attrs==23.1.0
6
+ certifi==2023.11.17
7
+ charset-normalizer==3.3.2
8
+ click==8.1.7
9
+ colorama==0.4.6
10
+ contourpy==1.2.0
11
+ cycler==0.12.1
12
+ diskcache==5.6.3
13
+ exceptiongroup==1.2.0
14
+ fastapi==0.105.0
15
+ ffmpy==0.3.1
16
+ filelock==3.13.1
17
+ fonttools==4.46.0
18
+ fsspec==2023.12.2
19
+ gradio==4.10.0
20
+ gradio_client==0.7.3
21
+ h11==0.14.0
22
+ httpcore==1.0.2
23
+ httpx==0.25.2
24
+ huggingface-hub==0.19.4
25
+ idna==3.6
26
+ importlib-resources==6.1.1
27
+ Jinja2==3.1.2
28
+ jsonschema==4.20.0
29
+ jsonschema-specifications==2023.11.2
30
+ kiwisolver==1.4.5
31
+ llama_cpp_python==0.2.23
32
+ markdown-it-py==3.0.0
33
+ MarkupSafe==2.1.3
34
+ matplotlib==3.8.2
35
+ mdurl==0.1.2
36
+ numpy==1.26.2
37
+ orjson==3.9.10
38
+ packaging==23.2
39
+ pandas==2.1.4
40
+ Pillow==10.1.0
41
+ pydantic==2.5.2
42
+ pydantic_core==2.14.5
43
+ pydub==0.25.1
44
+ Pygments==2.17.2
45
+ pyparsing==3.1.1
46
+ python-dateutil==2.8.2
47
+ python-multipart==0.0.6
48
+ pytz==2023.3.post1
49
+ PyYAML==6.0.1
50
+ referencing==0.32.0
51
+ requests==2.31.0
52
+ rich==13.7.0
53
+ rpds-py==0.13.2
54
+ semantic-version==2.10.0
55
+ shellingham==1.5.4
56
+ six==1.16.0
57
+ sniffio==1.3.0
58
+ starlette==0.27.0
59
+ tomlkit==0.12.0
60
+ toolz==0.12.0
61
+ tqdm==4.66.1
62
+ typer==0.9.0
63
+ typing_extensions==4.9.0
64
+ tzdata==2023.3
65
+ urllib3==2.1.0
66
+ uvicorn==0.24.0.post1
67
+ websockets==11.0.3
68
+ zipp==3.17.0