Spaces:
Runtime error
Runtime error
added api url
Browse files
app.py
CHANGED
@@ -5,28 +5,44 @@ from prompts import PROMPT_LIST
|
|
5 |
import streamlit as st
|
6 |
import random
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def process(text: str,
|
11 |
model_name: str,
|
12 |
max_len: int,
|
13 |
temp: float,
|
14 |
top_k: int,
|
15 |
-
top_p: float
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
30 |
|
31 |
st.set_page_config(page_title="Indonesian GPT-2 Demo")
|
32 |
|
@@ -86,9 +102,8 @@ if st.button("Run"):
|
|
86 |
max_len=max_len,
|
87 |
temp=temp,
|
88 |
top_k=top_k,
|
89 |
-
top_p=top_p
|
90 |
-
|
91 |
-
|
92 |
-
st.write(result["result"].replace("\n", " \n"))
|
93 |
st.text("English translation")
|
94 |
-
st.write(translate(result
|
|
|
5 |
import streamlit as st
|
6 |
import random
|
7 |
|
8 |
+
headers = {"Authorization": f"Bearer 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"}
|
9 |
+
MODELS = {
|
10 |
+
"GPT-2 Small": {
|
11 |
+
"url": "https://api-inference.huggingface.co/models/flax-community/gpt2-small-indonesian"
|
12 |
+
},
|
13 |
+
"GPT-2 Medium": {
|
14 |
+
"url": "https://api-inference.huggingface.co/models/flax-community/gpt2-medium-indonesian"
|
15 |
+
},
|
16 |
+
}
|
17 |
+
|
18 |
+
|
19 |
+
def query(payload, model_name):
|
20 |
+
data = json.dumps(payload)
|
21 |
+
response = requests.request("POST", MODELS[model_name]["url"], headers=headers, data=data)
|
22 |
+
return json.loads(response.content.decode("utf-8"))
|
23 |
+
|
24 |
|
25 |
def process(text: str,
|
26 |
model_name: str,
|
27 |
max_len: int,
|
28 |
temp: float,
|
29 |
top_k: int,
|
30 |
+
top_p: float):
|
31 |
+
|
32 |
+
payload = {
|
33 |
+
"inputs": text,
|
34 |
+
"parameters": {
|
35 |
+
"max_new_tokens": max_len,
|
36 |
+
"top_k": top_k,
|
37 |
+
"top_p": top_p,
|
38 |
+
"temperature": temp,
|
39 |
+
"repetition_penalty": 2.0,
|
40 |
+
},
|
41 |
+
"options": {
|
42 |
+
"use_cache": True,
|
43 |
+
}
|
44 |
+
}
|
45 |
+
return query(payload, model_name)
|
46 |
|
47 |
st.set_page_config(page_title="Indonesian GPT-2 Demo")
|
48 |
|
|
|
102 |
max_len=max_len,
|
103 |
temp=temp,
|
104 |
top_k=top_k,
|
105 |
+
top_p=top_p)[0]["generated_text"]
|
106 |
+
|
107 |
+
st.write(result.replace("\n", " \n"))
|
|
|
108 |
st.text("English translation")
|
109 |
+
st.write(translate(result, "en", "id").replace("\n", " \n"))
|