Spaces:
Sleeping
Sleeping
File size: 1,528 Bytes
cf3dd5b 49d10cb 7a0ff0c 49d10cb cf3dd5b 49d10cb fb9e581 cf3dd5b 60842f4 49d10cb cf3dd5b 49d10cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig
from peft import PeftModel, PeftConfig
import streamlit as st
model_name = "TheBloke/Mistral-7B-Instruct-v0.2-GPTQ"
configm = AutoConfig.from_pretrained(model_name)
configm.quantization_config["disable_exllama"] = True
model = AutoModelForCausalLM.from_pretrained(model_name,
trust_remote_code=False,
revision="main",
config=configm
)
config = PeftConfig.from_pretrained("saanvi-bot/jayson")
model = PeftModel.from_pretrained(model, "saanvi-bot/jayson", peft_config = config)
# load tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
"""### Use Fine-tuned Model"""
intstructions_string = f"""convert into json format \n"""
prompt_template = lambda comment: f'''[INST] {intstructions_string} \n{comment} \n[/INST]'''
model.eval()
# Streamlit interface
st.title("Text to JSON Converter")
st.write("Enter the text you want to convert to JSON format:")
# Text input from the user
user_input = st.text_area("Input text", height=200)
# Convert input text to JSON
if st.button("Convert"):
prompt = prompt_template(user_input)
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(input_ids=inputs["input_ids"], max_new_tokens=200)
json_output = tokenizer.batch_decode(outputs)[0]
st.json(json_output)
|