version 1
Browse files- .gitignore +1 -0
- README.md +1 -0
- app.py +15 -0
- index.html +22 -6
- requirements.txt +7 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
env/
|
README.md
CHANGED
@@ -6,6 +6,7 @@ colorTo: yellow
|
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
license: openrail
|
|
|
9 |
---
|
10 |
|
11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
license: openrail
|
9 |
+
python_version: 3.10.6
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCasualLM
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("togethercomputer/GPT-NeoXT-Chat-Base-20B")
|
7 |
+
model = AutoModelForCausalLM.from_pretrained("togethercomputer/GPT-NeoXT-Chat-Base-20B", torch_dtype=torch.bfloat16)
|
8 |
+
|
9 |
+
@app.get("/gpt")
|
10 |
+
async def gpt(prompt: str, req: Request):
|
11 |
+
inputs = tokenizer("<human>: Hello!\n<bot>:", return_tensors='pt').to(model.device)
|
12 |
+
outputs = model.generate(**inputs, max_new_tokens=10, do_sample=True, temperature=0.8)
|
13 |
+
output_str = tokenizer.decode(outputs[0])
|
14 |
+
print(output_str)
|
15 |
+
return {"response": output_str}
|
index.html
CHANGED
@@ -8,12 +8,28 @@
|
|
8 |
</head>
|
9 |
<body>
|
10 |
<div class="card">
|
11 |
-
<h1>Welcome to
|
12 |
-
<p>
|
13 |
-
<
|
14 |
-
|
15 |
-
|
16 |
-
</p>
|
17 |
</div>
|
18 |
</body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
8 |
</head>
|
9 |
<body>
|
10 |
<div class="card">
|
11 |
+
<h1>Welcome to my GPT test environment!</h1>
|
12 |
+
<p>Enter a prompt in the textbox to get started</p>
|
13 |
+
<textarea name="prompt" id="prompt" cols="30" rows="10"></textarea>
|
14 |
+
<button id="submit">Submit</button>
|
15 |
+
<p id="response"></p>
|
|
|
16 |
</div>
|
17 |
</body>
|
18 |
+
<script>
|
19 |
+
const btn = document.querySelector("#button")
|
20 |
+
const textbox = document.querySelector("#prompt")
|
21 |
+
const res = document.querySelector("#response")
|
22 |
+
const prompt = textbox.value
|
23 |
+
fetch(`/gpt?prompt=${prompt}`)
|
24 |
+
.then(res => res.json())
|
25 |
+
.then(res => {
|
26 |
+
console.log(res)
|
27 |
+
res.textContent = "success"
|
28 |
+
})
|
29 |
+
.catch(err => {
|
30 |
+
console.log(err)
|
31 |
+
res.textContent = "failure"
|
32 |
+
})
|
33 |
+
|
34 |
+
</script>
|
35 |
</html>
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
anyio==3.6.2
|
2 |
+
fastapi==0.95.2
|
3 |
+
idna==3.4
|
4 |
+
pydantic==1.10.7
|
5 |
+
sniffio==1.3.0
|
6 |
+
starlette==0.27.0
|
7 |
+
typing_extensions==4.5.0
|