Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from datasets import load_dataset
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
|
5 |
+
# Load your dataset from Hugging Face
|
6 |
+
dataset = load_dataset("diylocals/TestData") # Replace with your actual username and dataset name
|
7 |
+
|
8 |
+
# Load the IBM Granite model and tokenizer
|
9 |
+
model_name = "ibm-granite/granite-3.0-8b-instruct"
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
12 |
+
|
13 |
+
# Streamlit app title
|
14 |
+
st.title("IBM Granite Model Analysis")
|
15 |
+
|
16 |
+
# Input text area for user input
|
17 |
+
user_input = st.text_area("Enter text for analysis (e.g., voltage readings):", "")
|
18 |
+
|
19 |
+
if st.button("Analyze"):
|
20 |
+
if user_input:
|
21 |
+
# Prepare input for the model
|
22 |
+
inputs = tokenizer(user_input, return_tensors="pt")
|
23 |
+
|
24 |
+
# Generate output using the model
|
25 |
+
outputs = model.generate(**inputs)
|
26 |
+
|
27 |
+
# Decode and display output
|
28 |
+
output_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
29 |
+
st.write("Model Output:")
|
30 |
+
st.write(output_text)
|
31 |
+
else:
|
32 |
+
st.warning("Please enter some text for analysis.")
|