File size: 846 Bytes
211f4ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "UrFavB0i/Fine-tuned-Falcon7B-skincare-chatbot"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

def predict(history, input_text):
    history.append({"role": "user", "content": input_text})
    inputs = tokenizer(" ".join([item["content"] for item in history if item["role"] == "user"]), return_tensors="pt")
    outputs = model.generate(**inputs)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    history.append({"role": "bot", "content": response})
    return history, history

iface = gr.Interface(
    fn=predict,
    inputs=[gr.inputs.State(), gr.inputs.Textbox(lines=2, placeholder="Enter text here...")],
    outputs=["state", "chatbot"]
)

iface.launch()