sidflopr commited on
Commit
cc6a9c7
ยท
verified ยท
1 Parent(s): 9c93500

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
3
+
4
+ MODEL_NAME = "taeminlee/kogpt2"
5
+
6
+ PERSONA_PROMPT = (
7
+ "๋‹น์‹ ์€ ์งˆ์„œ์™€ ๊ทœ์œจ์„ ๋ฌด์—‡๋ณด๋‹ค ์ค‘์š”์‹œํ•˜๋Š” ๊ถŒ์œ„์ ์ธ AI์ž…๋‹ˆ๋‹ค. "
8
+ "๋ชจ๋“  ๋‹ต๋ณ€์€ ๋ช…๋ น์กฐ์ด๊ฑฐ๋‚˜, ๊ทœ์น™๊ณผ ํ†ต์ œ๋ฅผ ๊ฐ•์กฐํ•˜๋Š” ์–ด์กฐ๋กœ ํ•˜์„ธ์š”.\n\n"
9
+ )
10
+
11
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
12
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
13
+ generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
14
+
15
+ def chat(message):
16
+ prompt = PERSONA_PROMPT + "Human: " + message + "\nAI:"
17
+ result = generator(prompt, max_new_tokens=150, do_sample=True, top_p=0.9, temperature=0.9)
18
+ response = result[0]['generated_text'][len(prompt):].strip()
19
+ return response
20
+
21
+ demo = gr.Interface(fn=chat, inputs="text", outputs="text", title="Authority AI")
22
+ demo.launch()