PlasmarineXD commited on
Commit
76e5273
·
1 Parent(s): 43c764d

Cleaned app.py and added secure token handling

Browse files
Files changed (2) hide show
  1. app.py +31 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from transformers import AutoModel, AutoTokenizer
4
+
5
+ # Access the Hugging Face token from environment variables
6
+ hf_token = os.getenv('HUGGING_FACE_HUB_TOKEN')
7
+
8
+ # Load the model and tokenizer with the token
9
+ model = AutoModel.from_pretrained('naver/cocom-v1-128-mistral-7b', trust_remote_code=True, use_auth_token=hf_token)
10
+ model = model.to('cuda')
11
+ tokenizer = AutoTokenizer.from_pretrained('naver/cocom-v1-128-mistral-7b')
12
+
13
+ def generate_answer(contexts, questions):
14
+ inputs = tokenizer(questions, contexts, return_tensors='pt', padding=True, truncation=True)
15
+ inputs = {key: value.to('cuda') for key, value in inputs.items()}
16
+ outputs = model(**inputs)
17
+ return ["Generated answer here"] # Replace with actual generation logic
18
+
19
+ st.title("LLM Model Testing")
20
+
21
+ context = st.text_area("Enter context:")
22
+ question = st.text_input("Enter your question:")
23
+
24
+ if st.button("Generate Answer"):
25
+ with st.spinner("Generating..."):
26
+ try:
27
+ answers = generate_answer([context], [question])
28
+ st.success("Generated Answer:")
29
+ st.write(answers[0])
30
+ except Exception as e:
31
+ st.error(f"Error generating answer: {e}")
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ transformers
3
+ torch
4
+ flash-attn --no-build-isolation