Yuchan
commited on
Update Inference.py
Browse files- Inference.py +22 -3
Inference.py
CHANGED
|
@@ -6,6 +6,7 @@ from tensorflow.keras import mixed_precision
|
|
| 6 |
import sentencepiece as spm
|
| 7 |
import os, json
|
| 8 |
import requests
|
|
|
|
| 9 |
|
| 10 |
print('1')
|
| 11 |
|
|
@@ -57,7 +58,7 @@ if not os.path.exists(MODEL_PATH):
|
|
| 57 |
|
| 58 |
if not os.path.exists(TOKENIZER_PATH):
|
| 59 |
download_file(
|
| 60 |
-
"https://huggingface.co/
|
| 61 |
TOKENIZER_PATH
|
| 62 |
)
|
| 63 |
|
|
@@ -225,5 +226,23 @@ def generate_text_topp(model, prompt, max_len=512, max_gen=512, p=0.9, temperatu
|
|
| 225 |
generated.append(int(next_token_id))
|
| 226 |
return ids_to_text(generated)
|
| 227 |
|
| 228 |
-
|
| 229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import sentencepiece as spm
|
| 7 |
import os, json
|
| 8 |
import requests
|
| 9 |
+
import gradio as gr
|
| 10 |
|
| 11 |
print('1')
|
| 12 |
|
|
|
|
| 58 |
|
| 59 |
if not os.path.exists(TOKENIZER_PATH):
|
| 60 |
download_file(
|
| 61 |
+
"https://huggingface.co/Yuchan5386/Respiso/resolve/main/bpe.model?download=true",
|
| 62 |
TOKENIZER_PATH
|
| 63 |
)
|
| 64 |
|
|
|
|
| 226 |
generated.append(int(next_token_id))
|
| 227 |
return ids_to_text(generated)
|
| 228 |
|
| 229 |
+
def gr_generate(prompt, max_len=512, max_gen=512, p=0.8, temperature=0.8):
|
| 230 |
+
return generate_text_topp(model, prompt, max_len=max_len, p=p, temperature=temperature)
|
| 231 |
+
|
| 232 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
| 233 |
+
iface = gr.Interface(
|
| 234 |
+
fn=gr_generate,
|
| 235 |
+
inputs=[
|
| 236 |
+
gr.Textbox(label="Prompt ์
๋ ฅ", placeholder="์ฌ๊ธฐ์ ๋ฌธ์ฅ ์
๋ ฅ...", lines=2),
|
| 237 |
+
gr.Slider(20, 512, value=150, step=1, label="Max length"),
|
| 238 |
+
gr.Slider(0.1, 1.0, value=0.8, step=0.05, label="Top-p"),
|
| 239 |
+
gr.Slider(0.1, 2.0, value=0.8, step=0.05, label="Temperature")
|
| 240 |
+
],
|
| 241 |
+
outputs=[
|
| 242 |
+
gr.Textbox(label="์์ฑ ๊ฒฐ๊ณผ", lines=10)
|
| 243 |
+
],
|
| 244 |
+
title="Cuma LM ํ
์คํธ ์์ฑ",
|
| 245 |
+
description="๊ฐ๋จํ Gradio UI๋ก Cuma ๋ชจ๋ธ ํ
์คํธ ์์ฑ ํ
์คํธ"
|
| 246 |
+
)
|
| 247 |
+
|
| 248 |
+
iface.launch()
|