Spaces:
Running
Running
File size: 1,190 Bytes
6c8173c 98bb7ed 154b403 98bb7ed 6d7dce8 154b403 98bb7ed 154b403 98bb7ed 6c8173c 42ce03d 6c8173c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import gradio as gr
import numpy as np
import pandas as pd
from transformers import pipeline
import torch
model = "GeneZC/MiniChat-2-3B"
generator=pipeline(task='text-generation', model=model)
tones = {
'natural': 'human, authentic',
'fluency': 'readable, clarified',
'formal': 'sophistocated',
'academic': 'technical and scholarly',
'simple': 'simple and easily understandable',
}
def generate(text, max_length):
x=generator(text, max_length=max_length, num_return_sequences=1)
return x
def respond(message, history, tone="natural", max_length=512):
prompt = f"<s> [|User|]Paraphrase this text in a more {tones[tone]} way: {message} </s>[|Assistant|]"
text = generate(prompt, max_length)
print(text)
text = text[0]["generated_text"]
text = text.split("[|Assistant|]", 1)[1]
return text
demo = gr.ChatInterface(
respond,
additional_inputs=[
gr.Dropdown(
["natural", "fluency", "formal", "academic", "simple"], label="Tone", value="natural"
),
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
],
)
if __name__ == "__main__":
demo.launch() |