Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
model_name = "UrFavB0i/Fine-tuned-Falcon7B-skincare-chatbot"
|
5 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
|
8 |
+
def predict(history, input_text):
|
9 |
+
history.append({"role": "user", "content": input_text})
|
10 |
+
inputs = tokenizer(" ".join([item["content"] for item in history if item["role"] == "user"]), return_tensors="pt")
|
11 |
+
outputs = model.generate(**inputs)
|
12 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
13 |
+
history.append({"role": "bot", "content": response})
|
14 |
+
return history, history
|
15 |
+
|
16 |
+
iface = gr.Interface(
|
17 |
+
fn=predict,
|
18 |
+
inputs=[gr.inputs.State(), gr.inputs.Textbox(lines=2, placeholder="Enter text here...")],
|
19 |
+
outputs=["state", "chatbot"]
|
20 |
+
)
|
21 |
+
|
22 |
+
iface.launch()
|