Spaces:
Paused
Paused
Create App1.py
Browse files
App1.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
MODEL_ID = "goonsai-com/civitaiprompts"
|
6 |
+
MODEL_VARIANT = "Q4_K_M" # The quantized version
|
7 |
+
|
8 |
+
print("Loading model...")
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(f"hf.co/{MODEL_ID}:{MODEL_VARIANT}")
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(
|
11 |
+
f"hf.co/{MODEL_ID}:{MODEL_VARIANT}",
|
12 |
+
torch_dtype=torch.float16,
|
13 |
+
device_map="auto"
|
14 |
+
)
|
15 |
+
|
16 |
+
def chat(prompt):
|
17 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
18 |
+
output = model.generate(
|
19 |
+
**inputs,
|
20 |
+
max_length=200,
|
21 |
+
temperature=0.7,
|
22 |
+
do_sample=True
|
23 |
+
)
|
24 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
25 |
+
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=chat,
|
28 |
+
inputs="text",
|
29 |
+
outputs="text",
|
30 |
+
title="CivitaI Prompt Model",
|
31 |
+
description="Type a prompt and get a response."
|
32 |
+
)
|
33 |
+
|
34 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|