plannist commited on
Commit
cdc1e2e
ยท
1 Parent(s): f9c8470
Files changed (1) hide show
  1. app.py +15 -7
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-Polyglot-5.8B"
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=256,
19
  do_sample=True,
20
- temperature=0.7,
21
  top_p=0.9,
22
  )
23
 
24
  def chat_fn(prompt):
25
  try:
26
- output = pipe(prompt)[0]["generated_text"]
27
- return output
 
 
28
  except Exception as e:
29
- return [f"Error: {str(e)}"]
 
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(fn=chat_fn, inputs="text", outputs="text", name="predict")
 
 
 
 
 
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()