abhattac commited on
Commit
91ec962
1 Parent(s): cfc5dce
Files changed (5) hide show
  1. .gitignore +1 -0
  2. README.md +1 -0
  3. app.py +15 -0
  4. index.html +22 -6
  5. 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 your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
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