test / app.py
ngrigg's picture
Update model loading to use AutoModelForCausalLM
8270298
raw
history blame
1.44 kB
import streamlit as st
import pandas as pd
import asyncio
from llama_models import process_text
from dotenv import load_dotenv
import os
# Load environment variables from .env file
load_dotenv()
async def process_csv(file):
df = pd.read_csv(file, header=None) # Read the CSV file without a header
descriptions = df[0].tolist() # Access the first column directly
SAMPLE_SIZE = min(5, len(descriptions)) # Adjust sample size as needed
descriptions = descriptions[:SAMPLE_SIZE]
model_name = "instruction-pretrain/finance-Llama3-8B" # Ensure this is the correct model name
results = []
for desc in descriptions:
result = await process_text(model_name, desc)
results.append(result)
df['predictions'] = results
return df
st.title("Finance Model Deployment")
st.write("""
### Upload a CSV file with company descriptions to extract key products, geographies, and important keywords:
""")
uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
if uploaded_file is not None:
if st.button("Predict"):
with st.spinner("Processing..."):
df = asyncio.run(process_csv(uploaded_file))
st.write(df)
st.download_button(
label="Download Predictions as CSV",
data=df.to_csv(index=False).encode('utf-8'),
file_name='predictions.csv',
mime='text/csv'
)