Spaces:
Runtime error
Runtime error
new
Browse files- __pycache__/screenshot.cpython-37.pyc +0 -0
- __pycache__/spaces_info.cpython-37.pyc +0 -0
- app.py +33 -16
- requirements.txt +2 -0
__pycache__/screenshot.cpython-37.pyc
ADDED
Binary file (2.97 kB). View file
|
|
__pycache__/spaces_info.cpython-37.pyc
ADDED
Binary file (2.99 kB). View file
|
|
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
import json
|
4 |
import os
|
|
|
5 |
from screenshot import (
|
6 |
before_prompt,
|
7 |
prompt_to_generation,
|
@@ -10,11 +11,13 @@ from screenshot import (
|
|
10 |
js_load_script,
|
11 |
)
|
12 |
from spaces_info import description, examples, initial_prompt_value
|
|
|
|
|
13 |
|
14 |
#API_URL = os.getenv("API_URL")
|
15 |
#HF_API_TOKEN = os.getenv("HF_API_TOKEN")
|
16 |
|
17 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
18 |
HF_API_TOKEN = "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"
|
19 |
|
20 |
def query(payload):
|
@@ -30,7 +33,7 @@ def inference(input_sentence, max_length, sample_or_greedy, seed=42):
|
|
30 |
"max_new_tokens": max_length,
|
31 |
"top_p": 0.9,
|
32 |
"do_sample": True,
|
33 |
-
"seed": seed,
|
34 |
"early_stopping": False,
|
35 |
"length_penalty": 0.0,
|
36 |
"eos_token_id": None,
|
@@ -39,29 +42,43 @@ def inference(input_sentence, max_length, sample_or_greedy, seed=42):
|
|
39 |
parameters = {
|
40 |
"max_new_tokens": max_length,
|
41 |
"do_sample": False,
|
42 |
-
"seed": seed,
|
43 |
"early_stopping": False,
|
44 |
"length_penalty": 0.0,
|
45 |
"eos_token_id": None,
|
46 |
}
|
47 |
|
48 |
payload = {"inputs": input_sentence, "parameters": parameters,"options" : {"use_cache": False} }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
data = query(payload)
|
51 |
|
52 |
-
if "error" in data:
|
53 |
-
|
54 |
|
55 |
-
generation = data[0]["generated_text"].split(input_sentence, 1)[1]
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
65 |
|
66 |
|
67 |
if __name__ == "__main__":
|
|
|
2 |
import requests
|
3 |
import json
|
4 |
import os
|
5 |
+
from transformers import
|
6 |
from screenshot import (
|
7 |
before_prompt,
|
8 |
prompt_to_generation,
|
|
|
11 |
js_load_script,
|
12 |
)
|
13 |
from spaces_info import description, examples, initial_prompt_value
|
14 |
+
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer, set_seed
|
15 |
+
|
16 |
|
17 |
#API_URL = os.getenv("API_URL")
|
18 |
#HF_API_TOKEN = os.getenv("HF_API_TOKEN")
|
19 |
|
20 |
+
API_URL = "https://api-inference.huggingface.co/models/hf-internal-testing/tiny-random-bloom"
|
21 |
HF_API_TOKEN = "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"
|
22 |
|
23 |
def query(payload):
|
|
|
33 |
"max_new_tokens": max_length,
|
34 |
"top_p": 0.9,
|
35 |
"do_sample": True,
|
36 |
+
#"seed": seed,
|
37 |
"early_stopping": False,
|
38 |
"length_penalty": 0.0,
|
39 |
"eos_token_id": None,
|
|
|
42 |
parameters = {
|
43 |
"max_new_tokens": max_length,
|
44 |
"do_sample": False,
|
45 |
+
#"seed": seed,
|
46 |
"early_stopping": False,
|
47 |
"length_penalty": 0.0,
|
48 |
"eos_token_id": None,
|
49 |
}
|
50 |
|
51 |
payload = {"inputs": input_sentence, "parameters": parameters,"options" : {"use_cache": False} }
|
52 |
+
model_name = 'bigscience/bloomz-560m'
|
53 |
+
pipe = pipeline("text-generation",
|
54 |
+
model = model_name,
|
55 |
+
tokenizer = model_name,
|
56 |
+
max_new_tokens = max_length,
|
57 |
+
do_sample = False,
|
58 |
+
length_penalty = 0.0,
|
59 |
+
early_stopping = False,
|
60 |
+
eos_token_id = None
|
61 |
+
)
|
62 |
+
res = pipe(input_sentence)
|
63 |
+
generation = res["generated_text"]
|
64 |
|
65 |
+
#data = query(payload)
|
66 |
|
67 |
+
#if "error" in data:
|
68 |
+
# return (None, None, f"<span style='color:red'>ERROR: {data['error']} </span>")
|
69 |
|
70 |
+
#generation = data[0]["generated_text"].split(input_sentence, 1)[1]
|
71 |
+
|
72 |
+
# return (
|
73 |
+
# before_prompt
|
74 |
+
# + input_sentence
|
75 |
+
# + prompt_to_generation
|
76 |
+
# + generation
|
77 |
+
# + after_generation,
|
78 |
+
# data[0]["generated_text"],
|
79 |
+
# "",
|
80 |
+
# )
|
81 |
+
return generation
|
82 |
|
83 |
|
84 |
if __name__ == "__main__":
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
accelerate
|