Spaces:
Runtime error
Runtime error
update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from peft import PeftModel, PeftConfig
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
|
5 |
+
peft_model_id = "LLMPrompGenAI/LLMPromptGen-AI"
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(peft_model_id, return_dict=True, device_map='auto')
|
7 |
+
# tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
|
8 |
+
mixtral_tokenizer = AutoTokenizer.from_pretrained("mistralai/Mixtral-8x7B-v0.1")
|
9 |
+
|
10 |
+
def input_from_text(text):
|
11 |
+
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]"
|
12 |
+
|
13 |
+
def get_instruction(text):
|
14 |
+
inputs = mixtral_tokenizer(input_from_text(text), return_tensors="pt")
|
15 |
+
|
16 |
+
outputs = model.generate(
|
17 |
+
**inputs,
|
18 |
+
max_new_tokens=150,
|
19 |
+
generation_kwargs={"repetition_penalty" : 1.7}
|
20 |
+
)
|
21 |
+
print(mixtral_tokenizer.decode(outputs[0], skip_special_tokens=True))
|
22 |
+
return mixtral_tokenizer.decode(outputs[0], skip_special_tokens=True).split("[/INST]")[1]
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
# make a gradio interface
|
26 |
+
import gradio as gr
|
27 |
+
|
28 |
+
gr.Interface(
|
29 |
+
get_instruction,
|
30 |
+
[
|
31 |
+
gr.Textbox(lines=10, label="LLM Response"),
|
32 |
+
],
|
33 |
+
gr.Textbox(label="LLM Predicted Prompt"),
|
34 |
+
title="LLM-Prompt-Predictor",
|
35 |
+
description="Prompt Predictor Based on LLM Response",
|
36 |
+
).launch()
|