gradio: Increase `httpx` timeout to prevent requests from erroring out
Describe the bug
I’m developing a chatbot based on the RAG-QA.
I’m getting an Error on the Gradio front-end even though the backend works properly.
I’m uploading 1 page from Wikipedia using LangChain WikipediaLoader. Then creating a vector db using FAISS.
I’ve enabled logging and it looks as below:
2023-08-09 07:40:14 INFO [vector_store] Creating index...
2023-08-09 07:40:14 WARNING [langchain.text_splitter] Created a chunk of size 2518, which is longer than the specified 500
2023-08-09 07:40:14 WARNING [langchain.text_splitter] Created a chunk of size 793, which is longer than the specified 500
2023-08-09 07:40:14 WARNING [langchain.text_splitter] Created a chunk of size 2212, which is longer than the specified 500
2023-08-09 07:40:14 WARNING [langchain.text_splitter] Created a chunk of size 790, which is longer than the specified 500
Batches: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:03<00:00, 3.90s/it]
2023-08-09 07:40:18 INFO [faiss.loader] Loading faiss.
2023-08-09 07:40:18 INFO [faiss.loader] Successfully loaded faiss.
2023-08-09 07:40:18 INFO [vector_store] Index created successfully!
2023-08-09 07:40:18 INFO [common_utils] create_index took: 3.96 seconds
2023-08-09 07:40:18 INFO [vector_store] wikipedia data uploaded successfully!
In total it takes 3.96 seconds for the index creation.
I’m getting the Error on the Gradio front-end where I’m displaying the Status of the upload if it’s successful or not in the gr.Textbox()
Any help please?
Have you searched existing issues? 🔎
- I have searched and found no existing issues
Reproduction
Create the upload button as below:
with gr.Blocks(title="Demo", theme=gr.themes.Soft()) as demo:
with gr.Column(scale=1):
upload_success = gr.Textbox(
label="Success of the Upload",
placeholder="Success status for the data upload would appear here",
interactive=False,
queue=False
)
page = gr.Textbox(
label="Enter Wikipedia page names",
placeholder="Type the Wikipedia page names here",
value="2022 FIFA World Cup"
)
b_page = gr.Button("Load Wikipedia Pages")
b_page.click(
fn=load_wiki_pages,
inputs=page,
outputs=upload_success
)
demo.queue().launch(share=True)
NOTE: I need to use demo.queue() because I’m developing a RAG-QA Chatbot. Inside chatbot, I’m streaming the response with:
for char in response:
history[-1][1] += char
time.sleep(0.03)
yield history
Loading and creating the vector store as below:
from langchain.document_loaders import WikipediaLoader
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import FAISS
from langchain.embeddings.openai import OpenAIEmbeddings
docs = WikipediaLoader(query=page, load_max_docs=1).load()
text_splitter = CharacterTextSplitter(
chunk_size=500,
chunk_overlap=100,
separator="\n",
)
documents = text_splitter.split_documents(docs)
# Vector store using Facebook AI Similarity Search
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
index = FAISS.from_documents(documents, embeddings)
Screenshot
Originally it looks as below:
On uploading and creating the index from Wikipedia page:
Logs
No response
System Info
gradio 3.27.0
gradio_client 0.3.0
langchain 0.0.228
wikipedia 1.4.0
### Severity
Blocking usage of gradio
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 23 (6 by maintainers)
@piwawa you can use this script to change the httpx timeout:
Hey, I am running a gradio instance within a docker container and query it via the API from the host machine.
This exact issue seems to be a problem with the Client class imported from gradio_client. By running a simple API call as showed in the simple tutorial, all my request time out after 5s.
I edited the same line in the _config.py file of httpx as suggested by @chintan-donda and it works. Posting here since this seems to be the exact same issue
Thanks a lot!
Manually change the value in this line to higher number, say 30.
DEFAULT_TIMEOUT_CONFIG = Timeout(timeout=30.0)