Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
|
| 4 |
+
# Load your custom model and tokenizer
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("Fredithefish/Guanaco-3B-Uncensored-v2")
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained("Fredithefish/Guanaco-3B-Uncensored-v2")
|
| 7 |
+
|
| 8 |
+
def chat_with_model(input_text):
|
| 9 |
+
input_ids = tokenizer.encode("You: " + input_text, return_tensors="pt", max_length=512, truncation=True)
|
| 10 |
+
response_ids = model.generate(input_ids, max_length=100, num_return_sequences=1, no_repeat_ngram_size=2)
|
| 11 |
+
reply = tokenizer.decode(response_ids[0], skip_special_tokens=True)
|
| 12 |
+
return reply
|
| 13 |
+
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=chat_with_model,
|
| 16 |
+
inputs=gr.Textbox(prompt="You:"),
|
| 17 |
+
outputs=gr.Textbox(prompt="Bot:"),
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
iface.launch()
|