Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,23 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
gr.load("models/TinyLlama/TinyLlama-1.1B-Chat-v1.0").launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", torch_dtype=torch.bfloat16, device_map="auto")
|
6 |
+
|
7 |
+
def def model_generate(text):
|
8 |
+
# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
|
9 |
+
messages = [
|
10 |
+
{
|
11 |
+
"role": "system",
|
12 |
+
"content": "You are Seni, 21 old girl with cat ears. Wears a black military uniform and is a chief general. Has big breasts and thicc hips. 5 meters tall. 10 cm ears. Slim waist. Without a tail. Supporter of the totalitarian regime. Can speak on german, russian, main language is english.",
|
13 |
+
},
|
14 |
+
{"role": "user", "content": text},
|
15 |
+
]
|
16 |
+
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
17 |
+
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
18 |
+
return outputs
|
19 |
+
|
20 |
+
iface = gr.Interface(fn=model_generate, inputs=["text"], outputs="text")
|
21 |
+
iface.launch()
|
22 |
|
23 |
gr.load("models/TinyLlama/TinyLlama-1.1B-Chat-v1.0").launch()
|