Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 3 |
+
|
| 4 |
+
MODEL_ID = "janajankovic/autotrain-juhh6-uwiv9" # your fine-tuned model repo id
|
| 5 |
+
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_ID)
|
| 8 |
+
|
| 9 |
+
pipe = pipeline(
|
| 10 |
+
"text-generation",
|
| 11 |
+
model=model,
|
| 12 |
+
tokenizer=tokenizer,
|
| 13 |
+
max_new_tokens=256,
|
| 14 |
+
do_sample=True,
|
| 15 |
+
top_p=0.9,
|
| 16 |
+
temperature=0.7,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def chat_fn(history, user_input):
|
| 21 |
+
# simple prompt: previous turns concatenated
|
| 22 |
+
text = ""
|
| 23 |
+
for turn in history:
|
| 24 |
+
text += f"Uporabnik: {turn[0]}\nModel: {turn[1]}\n"
|
| 25 |
+
text += f"Uporabnik: {user_input}\nModel:"
|
| 26 |
+
|
| 27 |
+
out = pipe(text)[0]["generated_text"]
|
| 28 |
+
reply = out.split("Model:")[-1].strip()
|
| 29 |
+
history.append((user_input, reply))
|
| 30 |
+
return history, ""
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
chatbot = gr.Chatbot(label="Slovenski finetune")
|
| 35 |
+
msg = gr.Textbox(label="Vnos")
|
| 36 |
+
clear = gr.Button("Počisti")
|
| 37 |
+
|
| 38 |
+
def user_send(message, chat_history):
|
| 39 |
+
chat_history = chat_history or []
|
| 40 |
+
return "", chat_fn(chat_history, message)[0]
|
| 41 |
+
|
| 42 |
+
msg.submit(user_send, [msg, chatbot], [msg, chatbot])
|
| 43 |
+
clear.click(lambda: ([], ""), None, [chatbot, msg], queue=False)
|
| 44 |
+
|
| 45 |
+
demo.launch()
|