plannist
commited on
Commit
ยท
cdc1e2e
1
Parent(s):
f9c8470
app.py
CHANGED
|
@@ -2,7 +2,7 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
| 2 |
import torch
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
model_name = "beomi/KoAlpaca-
|
| 6 |
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
model = AutoModelForCausalLM.from_pretrained(
|
|
@@ -15,18 +15,21 @@ pipe = pipeline(
|
|
| 15 |
"text-generation",
|
| 16 |
model=model,
|
| 17 |
tokenizer=tokenizer,
|
| 18 |
-
max_new_tokens=
|
| 19 |
do_sample=True,
|
| 20 |
-
temperature=0.
|
| 21 |
top_p=0.9,
|
| 22 |
)
|
| 23 |
|
| 24 |
def chat_fn(prompt):
|
| 25 |
try:
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
with gr.Blocks() as demo:
|
|
@@ -47,7 +50,12 @@ with gr.Blocks() as demo:
|
|
| 47 |
demo.load(chat_fn, inputs=input_box, outputs=output_box)
|
| 48 |
|
| 49 |
# โ
API endpoint๋ก ์ฌ์ฉํ Interface ๊ฐ์ฒด ๋ฑ๋ก
|
| 50 |
-
api_demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
if __name__ == "__main__":
|
| 53 |
demo.queue()
|
|
|
|
| 2 |
import torch
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
model_name = "beomi/KoAlpaca-7B"
|
| 6 |
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
| 15 |
"text-generation",
|
| 16 |
model=model,
|
| 17 |
tokenizer=tokenizer,
|
| 18 |
+
max_new_tokens=128,
|
| 19 |
do_sample=True,
|
| 20 |
+
temperature=0.5,
|
| 21 |
top_p=0.9,
|
| 22 |
)
|
| 23 |
|
| 24 |
def chat_fn(prompt):
|
| 25 |
try:
|
| 26 |
+
outputs = pipe(prompt)
|
| 27 |
+
# text-generation ํ์ดํ๋ผ์ธ์ ์ถ๋ ฅ์ ๋ฆฌ์คํธ ํํ๋ก ๋ฐํ๋๋ฉฐ,
|
| 28 |
+
# ๊ฐ ์ถ๋ ฅ์ generated_text ํค๋ฅผ ํฌํจํฉ๋๋ค
|
| 29 |
+
return outputs[0]["generated_text"]
|
| 30 |
except Exception as e:
|
| 31 |
+
print(f"Error in chat_fn: {str(e)}") # ๋๋ฒ๊น
์ ์ํ ์๋ฌ ๋ก๊น
์ถ๊ฐ
|
| 32 |
+
return f"Error: {str(e)}"
|
| 33 |
|
| 34 |
|
| 35 |
with gr.Blocks() as demo:
|
|
|
|
| 50 |
demo.load(chat_fn, inputs=input_box, outputs=output_box)
|
| 51 |
|
| 52 |
# โ
API endpoint๋ก ์ฌ์ฉํ Interface ๊ฐ์ฒด ๋ฑ๋ก
|
| 53 |
+
api_demo = gr.Interface(
|
| 54 |
+
fn=chat_fn,
|
| 55 |
+
inputs="text",
|
| 56 |
+
outputs="text",
|
| 57 |
+
api_name="predict" # API ์๋ํฌ์ธํธ ์ด๋ฆ ๋ช
์
|
| 58 |
+
)
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
| 61 |
demo.queue()
|