Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,49 @@
|
|
1 |
-
|
2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
-
import streamlit as st
|
4 |
-
import numpy as np
|
5 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
|
|
|
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
from google.protobuf.struct_pb2 import Value
|
13 |
|
|
|
|
|
|
1 |
+
from unsloth import FastLanguageModel
|
|
|
|
|
|
|
2 |
import torch
|
3 |
+
import streamlit as st
|
4 |
+
from transformers import TextStreamer
|
5 |
+
|
6 |
+
|
7 |
+
@st.cache_resource
|
8 |
+
def load_model():
|
9 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
10 |
+
model_name = "lora_model",
|
11 |
+
max_seq_length = 2048,
|
12 |
+
dtype = None,
|
13 |
+
load_in_4bit = True,
|
14 |
+
)
|
15 |
+
FastLanguageModel.for_inference(model)
|
16 |
+
return model, tokenizer
|
17 |
+
|
18 |
+
model, tokenizer = load_model()
|
19 |
+
|
20 |
+
st.title("Activity and Emission Prediction")
|
21 |
+
st.write("Match the potential use case with the corresponding activity and emission values based on provided context.")
|
22 |
+
|
23 |
+
|
24 |
+
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
25 |
+
|
26 |
+
### Instruction:
|
27 |
+
{}
|
28 |
+
|
29 |
+
### Input:
|
30 |
+
{}
|
31 |
+
|
32 |
+
### Response:
|
33 |
+
{}"""
|
34 |
|
35 |
+
instruction = st.text_input("Instruction", "Match the potential use case with the corresponding activity and emission values based on the provided context.")
|
36 |
+
input_text = st.text_area("Input", "Doğal Gaz Kullanımı, Gaz Faturası Yönetimi, Isınma Maliyetleri, Enerji Tasarrufu, Gaz Dağıtımı")
|
37 |
|
38 |
+
# Button to trigger model generation
|
39 |
+
if st.button("Generate Response"):
|
40 |
+
with st.spinner("Generating response..."):
|
41 |
+
# Prepare inputs for the model
|
42 |
+
formatted_prompt = alpaca_prompt.format(instruction, input_text, "")
|
43 |
+
inputs = tokenizer([formatted_prompt], return_tensors="pt").to("cuda")
|
44 |
|
45 |
+
outputs = model.generate(**inputs, max_new_tokens=128)
|
46 |
+
response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
47 |
|
48 |
+
st.write("### Response")
|
49 |
+
st.write(response_text)
|