Spaces:
Build error
Build error
Oscar Dilley commited on
Commit ·
8aec0fe
1
Parent(s): f6ffde9
version1
Browse filesFiles changed (3)
- .gitignoreAdded+4
- app.py+68-2
- requirements.txtAdded+2
1234venv/env/.venv/.env/1234import streamlit as stx = st.slider('Select a value')st.write(x, 'squared is', x * x)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970import streamlit as stfrom transformers import AutoTokenizer, AutoModelForCausalLMimport time# Streamlit setupst.title("Telco Chat Bot")st.subheader("Smart Internet Lab")st.page_link("https://github.com/Ali-maatouk/Tele-LLMs", label="Tele-LLMs backend", icon="📱")# Add text giving creditcol1, col2 = st.columns(2)if 'conversation' not in st.session_state:st.session_state.conversation = []user_input = st.text_input("You:", "") # user input# Model functions:@st.cache_resource(show_spinner=False)def load_model():""" Load model from Hugging face."""success_placeholder = st.empty()with st.spinner("Loading model... please wait"):model_name = "AliMaatouk/TinyLlama-1.1B-Tele" # Replace with the correct model nametokenizer = AutoTokenizer.from_pretrained(model_name, torch_dtype="auto")model = AutoModelForCausalLM.from_pretrained(model_name)success_placeholder.success("Model loaded successfully!", icon="🔥")time.sleep(2)success_placeholder.empty()return model, tokenizerdef generate_response(user_input):""" Query the model. """success_placeholder = st.empty()with st.spinner("Thinking..."):inputs = tokenizer(user_input, return_tensors="pt")#outputs = model.generate(**inputs, max_length=1000, pad_token_id=tokenizer.eos_token_id)outputs = model.generate(**inputs, max_new_tokens=100)generated_tokens = outputs[0, len(inputs['input_ids'][0]):]success_placeholder.success("Response generated!", icon="✅")time.sleep(2)success_placeholder.empty()return tokenizer.decode(generated_tokens, skip_special_tokens=True)# RUNTIME EVENTS:# Load model and tokenizermodel, tokenizer = load_model()# Submit button to send the querywith col1:if st.button("send"):if user_input:st.session_state.conversation.append({"role": "user", "content": user_input})# Querying model# Add a loading spinner during model loadingresponse = generate_response(user_input)# Display bot responsest.session_state.conversation.append({"role": "bot", "content": response})# Clear button to resetwith col2:if st.button("clear chat"):if user_input:st.session_state.conversation = []# Display conversation historyfor chat in st.session_state.conversation:if chat['role'] == 'user':st.write(f"You: {chat['content']}")else:st.write(f"Bot: {chat['content']}")
12streamlittransformers.gitignoreAdded+4
app.py+68-2
requirements.txtAdded+2