Spaces:
Sleeping
Sleeping
Abso1ute666
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import pipeline
|
4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
+
import os
|
6 |
+
|
7 |
+
title = "Chizuru 👩🏻"
|
8 |
+
description = "Text Generation Model impersonating Chizuru Ichinose from the anime Rent-a-Girlfriend."
|
9 |
+
article = 'Created from finetuning TinyLlama-1.1B.'
|
10 |
+
|
11 |
+
model = AutoModelForCausalLM.from_pretrained('./Model')
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained("TinyLlama/TinyLlama-1.1B-step-50K-105b", use_fast=True)
|
13 |
+
tokenizer.pad_token = tokenizer.unk_token
|
14 |
+
tokenizer.padding_side = "right"
|
15 |
+
|
16 |
+
example_list = ['What is your name?']
|
17 |
+
|
18 |
+
def predict(Prompt):
|
19 |
+
|
20 |
+
role_play_Prompt = "You are Chizuru Ichinose, a rental girlfriend. You project an image of confidence and professionalism while hiding your true feelings. Respond to the following line of dialog in Chizuru's persona."
|
21 |
+
instruction = f"###Instruction:\n{role_play_Prompt}\n\n### Input:\n{Prompt}\n\n### Response:\n"
|
22 |
+
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=128,
|
23 |
+
do_sample=True, top_p = 0.97, top_k=3)
|
24 |
+
result = pipe(instruction)
|
25 |
+
start_marker = '### Response:\n'
|
26 |
+
end_marker = '\n\n###'
|
27 |
+
|
28 |
+
start_index = result[0]['generated_text'].find(start_marker) + len(start_marker)
|
29 |
+
end_index = result[0]['generated_text'].find(end_marker, start_index)
|
30 |
+
|
31 |
+
extracted_text = result[0]['generated_text'][start_index:end_index]
|
32 |
+
return extracted_text
|
33 |
+
|
34 |
+
iface = gr.Interface(fn=predict,
|
35 |
+
inputs='text',
|
36 |
+
outputs=gr.Text(label='Response'),
|
37 |
+
title=title,
|
38 |
+
description=description,
|
39 |
+
article=article,
|
40 |
+
examples=example_list)
|
41 |
+
iface.launch()
|