Jimin Park
commited on
Commit
·
71e55e7
1
Parent(s):
512081c
updated app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import transformers
|
| 3 |
import gradio as gr
|
|
@@ -78,7 +118,7 @@ demo = gr.ChatInterface(
|
|
| 78 |
if __name__ == "__main__":
|
| 79 |
demo.launch()
|
| 80 |
|
| 81 |
-
|
| 82 |
import torch
|
| 83 |
import transformers
|
| 84 |
import gradio as gr
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
chatbot = pipeline(model="ivwhy/lora_model")
|
| 5 |
+
|
| 6 |
+
message_list = []
|
| 7 |
+
response_list = []
|
| 8 |
+
|
| 9 |
+
def chat_function(message, history, system_prompt, max_new_tokens, temperature):
|
| 10 |
+
messages = [{"role":"system","content":system_prompt},
|
| 11 |
+
{"role":"user","content":message}]
|
| 12 |
+
prompt = pipeline.tokenizer.apply_chat_template(
|
| 13 |
+
messages,
|
| 14 |
+
tokenize=False,
|
| 15 |
+
add_generation_prompt=True,)
|
| 16 |
+
terminators = [
|
| 17 |
+
pipeline.tokenizer.eos_token_id,
|
| 18 |
+
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")]
|
| 19 |
+
outputs = pipeline(
|
| 20 |
+
prompt,
|
| 21 |
+
max_new_tokens = max_new_tokens,
|
| 22 |
+
eos_token_id = terminators,
|
| 23 |
+
do_sample = True,
|
| 24 |
+
temperature = 0.1,
|
| 25 |
+
top_p = 0.9,)
|
| 26 |
+
return outputs[0]["generated_text"][len(prompt):]
|
| 27 |
+
|
| 28 |
+
demo_chatbot = gr.ChatInterface(
|
| 29 |
+
chat_function,
|
| 30 |
+
textbox=gr.Textbox(placeholder="Enter message here", container=False, scale=7),
|
| 31 |
+
chatbot=gr.Chatbot(height=400),
|
| 32 |
+
additional_inputs=[
|
| 33 |
+
gr.Textbox("You are helpful AI", label="System Prompt"),
|
| 34 |
+
gr.Slider(500,4000, label="Max New Tokens"),
|
| 35 |
+
gr.Slider(0,1,label="Temperature")
|
| 36 |
+
])
|
| 37 |
+
|
| 38 |
+
demo_chatbot.launch()
|
| 39 |
+
|
| 40 |
+
''' =================================== OLD VERSION ==============================================
|
| 41 |
import torch
|
| 42 |
import transformers
|
| 43 |
import gradio as gr
|
|
|
|
| 118 |
if __name__ == "__main__":
|
| 119 |
demo.launch()
|
| 120 |
|
| 121 |
+
================================== OLD VER ==============================
|
| 122 |
import torch
|
| 123 |
import transformers
|
| 124 |
import gradio as gr
|