Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from peft import PeftModel, PeftConfig
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
|
5 |
+
peft_model_id = f"Bsbell21/llm_instruction_generator"
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(peft_model_id, return_dict=True, load_in_8bit=True, device_map='auto')
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
|
8 |
+
# Load the Lora model
|
9 |
+
# model = PeftModel.from_pretrained(model, peft_model_id)
|
10 |
+
|
11 |
+
def input_from_text(text):
|
12 |
+
return "<s>[INST]Use the provided input to create an instruction that could have been used to generate the response with an LLM.\n" + text + "[/INST]"
|
13 |
+
|
14 |
+
def get_instruction(text):
|
15 |
+
inputs = mixtral_tokenizer(input_from_text(text), return_tensors="pt")
|
16 |
+
|
17 |
+
outputs = merged_model.generate(
|
18 |
+
**inputs,
|
19 |
+
max_new_tokens=150,
|
20 |
+
generation_kwargs={"repetition_penalty" : 1.7}
|
21 |
+
)
|
22 |
+
# print(mixtral_tokenizer.decode(outputs[0], skip_special_tokens=True))
|
23 |
+
print(mixtral_tokenizer.decode(outputs[0], skip_special_tokens=True).split("[/INST]")[1])
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
# make a gradio interface
|
27 |
+
import gradio as gr
|
28 |
+
|
29 |
+
gr.Interface(
|
30 |
+
get_instruction,
|
31 |
+
[
|
32 |
+
gr.Textbox(lines=10, label="LLM Response"),
|
33 |
+
],
|
34 |
+
gr.Textbox(label="LLM Predicted Prompt"),
|
35 |
+
title="LLM-Prompt-Predictor",
|
36 |
+
description="Prompt Predictor Based on LLM Response",
|
37 |
+
).launch()
|