import tensorflow as tf import tensorflowhub as hub import pandas as pd import re import…
- User
import tensorflow as tf import tensorflow_hub as hub import pandas as pd import re import numpy as np import datetime import datefinder import gradio as gr
from sentence_transformers import SentenceTransformer retrieval_model_path = "model_jatin//" retrieval_model = SentenceTransformer(retrieval_model_path)
data = pd.read_csv('sales_portal.txt', sep="\t" ,encoding='cp1252',header=None)
headers = data.iloc[0] new_df = pd.DataFrame(data.values[1:], columns=headers)
new_df.rename(columns={' Query': 'user_query', 'Response': 'answer'}, inplace=True)
def get_most_similar_question(userText,history):
new_df['user_query'] = new_df['user_query'].str.lower() question_list = new_df["user_query"].to_list() question_embeddings = retrieval_model.encode(question_list) user_text_embedding = retrieval_model.encode([userText.lower()])# Calculate similarity scores similarity_scores = np.inner(user_text_embedding, question_embeddings).flatten() top_match_idx = np.argmax(similarity_scores) if similarity_scores[top_match_idx] == 0: return "Sorry, no similar questions were found for your query." matched_data = new_df.iloc[top_match_idx,[1]] return matched_data.values[0] # Returning the matched row as HTMLdummy_users = [ {"username": "jatin", "password": "qwer@345"}, {"username": "ajoy", "password": "qwer@345"}, {"username": "user3", "password": "pass3"}, {"username": "user4", "password": "pass4"}, {"username": "user5", "password": "pass5"} ] def authenticate_user(username, password): for user in dummy_users: if user["username"] == username and user["password"] == password: return True return False
gr.Markdown("##Ask questions in following formats..")
gr.Examples(["All india sellout value for 05 Jan 2022","GT sellout value for 05 Dec 2024"],[txt,txt_1],txt_3,combine,cache_examples=True)
gr.ChatInterface(get_most_similar_question,analytics_enabled=False).launch(auth=authenticate_user,inline=True, share=True,server_name= '0.0.0.0', server_port=7897)
I need to give images and pdf as output from my stored file ,using this similarity model only,hanld ethat,right now it workks for textual data only
- Assistant
- User
give me complete code
- Assistant
- User
return FileMessage( File "/home/jovyan/.local/lib/python3.8/site-packages/pydantic/main.py", line 176, in init self.pydantic_validator.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 1 validation error for FileMessage alt_text Input should be a valid string [type=string_type, input_value=<gradio.components.file.F...bject at 0x7f7c5250f490>, input_type=File] For further information visit https://errors.pydantic.dev/2.7/v/string_type
- Assistant
- User
just tell me which line changed
- Assistant
Sure, here are the specific lines that were changed or added to address the validation error:
components.append(gr.File(value=result['pdf'], label="Download associated PDF"))The change was to add the
labelparameter to thegr.Filecomponent to provide additional context, which helps ensure that it matches the expected input type and provides appropriate error-free output handling.So, the modified line is:
components.append(gr.File(value=result['pdf'], label="Download associated PDF"))This label helps clarify the purpose of the file being provided and resolves the validation error related to the file handling.
- User
cretae a chatbot UI in streamlit,where output can be image ,pdf or text
- Assistant
- User
make it run at port 2323 and server 0000
- Assistant
- User
File "/opt/conda/lib/python3.8/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 75, in exec_func_with_error_handling result = func() File "/opt/conda/lib/python3.8/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 574, in code_to_exec exec(code, module.dict) File "/home/jovyan/NlpSql/move.py", line 61, in st.image(response['image'], caption='Related Image') File "/opt/conda/lib/python3.8/site-packages/streamlit/runtime/metrics_util.py", line 408, in wrapped_func result = non_optional_func(*args, **kwargs) File "/opt/conda/lib/python3.8/site-packages/streamlit/elements/image.py", line 161, in image marshall_images( File "/opt/conda/lib/python3.8/site-packages/streamlit/elements/image.py", line 551, in marshall_images proto_img.url = image_to_url( File "/opt/conda/lib/python3.8/site-packages/streamlit/elements/image.py", line 398, in image_to_url url = runtime.get_instance().media_file_mgr.add(image, mimetype, image_id) File "/opt/conda/lib/python3.8/site-packages/streamlit/runtime/media_file_manager.py", line 224, in add file_id = self._storage.load_and_get_id( File "/opt/conda/lib/python3.8/site-packages/streamlit/runtime/memory_media_file_storage.py", line 115, in load_and_get_id file_data = self._read_file(path_or_data) File "/opt/conda/lib/python3.8/site-packages/streamlit/runtime/memory_media_file_storage.py", line 167, in _read_file raise MediaFileStorageError(f"Error opening '{filename}'") from ex
- Assistant
- User
for image and pdf it is saying not a valid path
- Assistant