Taking too much time to process simple request.
I am building streamlit app for language translation using this code but it is taking around 1 min to translate one sentence.
import streamlit as st
from langchain.chains import LLMChain
from langchain.llms import CTransformers
from langchain.prompts import PromptTemplate
Mistral configuration
config = {'max_new_tokens': 256, 'temperature': 0.8, 'context_length': 256}
llm = CTransformers(model="TheBloke/Mistral-7B-Instruct-v0.1-GGUF",
model_file="mistral-7b-instruct-v0.1.Q4_K_M.gguf",
config=config)
Streamlit app
st.title("Language Translation with Mistral")
Sidebar for selecting languages
language_options = ["English", "French", "Spanish", "German", "Chinese", "Japanese", "Russian", "Arabic", "Hindi", "Swahili"]
original_language = st.sidebar.selectbox("Select Original Language", language_options)
target_language = st.sidebar.selectbox("Select Target Language", language_options)
Input text box
input_text = st.text_area("Enter Text to Translate", "")
if st.button("Translate"):
Translate using Mistral
chunk_size = 100 # Adjust the chunk size as needed
chunks = [input_text[i:i + chunk_size] for i in range(0, len(input_text), chunk_size)]
translated_chunks = []
for chunk in chunks:
map_template = f"[INST] Translate the following text from {original_language} to {target_language}: {chunk} [/INST] "
map_prompt = PromptTemplate.from_template(map_template)
translate_chain = LLMChain(llm=llm, prompt=map_prompt)
translated_chunk = translate_chain.run({})
translated_chunks.append(translated_chunk)
translated_text = "".join(translated_chunks)
Display translated text
st.subheader("Translated Text:")
st.write(translated_text)