Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from unsloth import FastLanguageModel
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model, tokenizer = FastLanguageModel.from_pretrained("yourusername/lora_model", load_in_4bit=True)
|
| 6 |
+
FastLanguageModel.for_inference(model)
|
| 7 |
+
|
| 8 |
+
def chat(input_text):
|
| 9 |
+
messages = [{"role": "user", "content": input_text}]
|
| 10 |
+
inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
|
| 11 |
+
outputs = model.generate(inputs, max_new_tokens=128, temperature=1.0)
|
| 12 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 13 |
+
|
| 14 |
+
gr.Interface(fn=chat, inputs="text", outputs="text").launch()
|