File size: 1,382 Bytes
f5ca319
cb57e77
fff8547
02c818f
55198db
fff8547
76a5b75
9c94ae5
31ba077
a98fe93
9c94ae5
 
31ba077
9c94ae5
 
fff8547
5897134
31ba077
9c94ae5
31ba077
9c94ae5
31ba077
 
9c94ae5
 
 
 
31ba077
 
9c94ae5
31ba077
9c94ae5
c287fa9
 
ec6ee6b
 
 
76a5b75
 
ec6ee6b
 
 
9c94ae5
31ba077
 
 
 
 
 
 
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
47
48
49
50
from transformers import pipeline
from transformers import AutoModelForCausalLM, AutoTokenizer
import gradio as gr
from nltk.tokenize import sent_tokenize
import torch

model = "janny127/autotrain-pje3d-uvelc1"
tokenizer = AutoTokenizer.from_pretrained(model)

pipeline = pipeline(
    "text-generation",
    model=model,
    torch_dtype=torch.float16,
    device_map="auto",
)

def predict(prompt, history):
    # Prompt
    formatted_prompt = (
        f"### Human: {prompt}### Assistant:"
    )
    
    # Generate the Texts
    sequences = pipeline(
        formatted_prompt,
        do_sample=True,
        top_k=50,
        top_p = 0.7,
        num_return_sequences=1,
        repetition_penalty=1.1,
        max_new_tokens=500,
    )
    generated_text = sequences[0]['generated_text']

    final_result = generated_text.split("### Assistant:")[1]
    if " Human: " in final_result:
        final_result = final_result.split(" Human: ")[0]
    if " #" in final_result:
        final_result = final_result.split(" #")[0]
    
    # return generated_text.strip()
    return final_result.strip()

gr.ChatInterface(predict,
                 title="Tinyllama_chatBot",
                 description="Ask Tiny llama any questions",
                 examples=['How to cook a fish?', 'Who is the president of US now?']
                 ).launch()  # Launching the web interface.