File size: 746 Bytes
8296b33
 
 
 
e33812c
8296b33
 
e33812c
8296b33
 
e33812c
 
8296b33
 
 
 
 
 
 
 
e33812c
8296b33
 
 
 
e33812c
8296b33
 
 
e33812c
 
 
 
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
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_id = "cheimaguessim/marketing-chatbot-mistral-full"

tokenizer = AutoTokenizer.from_pretrained(model_id)

model = AutoModelForCausalLM.from_pretrained(
    model_id,
    device_map="auto",
    torch_dtype=torch.float16
)

def generate(prompt):
    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

    outputs = model.generate(
        **inputs,
        max_new_tokens=150,
        temperature=0.7
    )

    return tokenizer.decode(outputs[0], skip_special_tokens=True)

iface = gr.Interface(
    fn=generate,
    inputs="text",
    outputs="text",
    title="Marketing Chatbot"
)

iface.launch()