Spaces:
Sleeping
Sleeping
Tanuj commited on
Commit ·
2cf474e
1
Parent(s): f2c4e2e
Update requirements
Browse filesFiles changed (4)
- .gitignore+1
- app.py+4-3
- rag.py+15-13
- requirements.txt+4-1
1 unmodified line2341 unmodified line.DS_Store.venv/__pycache__/1 unmodified line23451 unmodified line.DS_Store.venv/__pycache__/.env
12345649 unmodified lines5657585960616235 unmodified lines9899100101102103104import gradio as grfrom pathlib import Pathfrom rag import is_allowed_filetype, upload_pdf_to_vectara, retrieve_chunksimport logging# ---------------------------49 unmodified linesReturns:str: Simulated or generated action and result."""return f"💬 Got your request: “{query}”. This would be processed by the language understanding agent system."def placeholder(feature_name: str = "unknown") -> str:35 unmodified linesfile_contents = file.read()upload_result = upload_pdf_to_vectara(file_contents, filepath.name)return f"Uploaded document: {upload_result['id']}"12345649 unmodified lines565758596061626335 unmodified lines99100101102103104105import gradio as grfrom pathlib import Pathfrom rag import is_allowed_filetype, upload_file_to_vectara, retrieve_chunksimport logging# ---------------------------49 unmodified linesReturns:str: Simulated or generated action and result."""chunks, response = retrieve_chunks(query, limit=5)return f"💬 Got {len(chunks)} chunks for your request: “{query}”. Response: {response}"def placeholder(feature_name: str = "unknown") -> str:35 unmodified linesfile_contents = file.read()upload_result = upload_file_to_vectara(file_contents, filepath.name)return f"Uploaded document: {upload_result['id']}"
12345650 unmodified lines575859606162636465666768694 unmodified lines7475767778798081828384856 unmodified lines929394959697989910010110230 unmodified lines13313413513613713813917 unmodified lines15715815916016116216380 unmodified lines244245246247248249250import jsonimport loggingimport osimport requestsfrom pprint import pprintfrom schemas import UploadResult50 unmodified lineswith open(filename, "w") as f:json.dump(response_json, f, indent=2)def upload_pdf_to_vectara(pdf_bytes: bytes, filename: str) -> UploadResult:"""Uploads a PDF file to Vectara for processing.Args:pdf_bytes (bytes): The PDF file content in bytes.filename (str): The name of the PDF file.Returns:None4 unmodified lines"""CORPUS_KEY = "YouTwo" # Replace with your actual corpus key# Check if pdf_bytes is providedif not pdf_bytes:raise IndexingError("No PDF bytes provided.")# Ensure valid filenameif not filename.endswith(".pdf"):raise IndexingError("Invalid filename. Please provide a filename ending with .pdf")# Replace with your actual corpus_key and API key6 unmodified lines"Accept": "application/json","x-api-key": api_key,}files = {'file': (filename, pdf_bytes, 'application/pdf')}try:response = requests.post(url, headers=headers, files=files)response.raise_for_status() # Raise an exception for HTTP errors30 unmodified linesstorage_usage=response_json["storage_usage"])# See https://docs.vectara.com/docs/rest-api/query-corpusdef retrieve_chunks(query: str) -> tuple[list[str], str]:"""Retrieves relevant chunks and a generated summary from the Vectara corpus based on the query.17 unmodified linespayload = {"query": query,"search": {"limit": 10, # Number of search results to retrieve# "reranker": {# "type": "customer_reranker",# "reranker_name": "Rerank_Multilingual_v1",80 unmodified linespdf_path = Path(FILEPATH).expanduser()with open(pdf_path, "rb") as f:pdf_bytes = f.read()upload_pdf_to_vectara(pdf_bytes, pdf_path.name)except Exception as e:raise IndexingError(f"Error occurred while uploading PDF: {e}")123456750 unmodified lines585960616263646566676869704 unmodified lines757677787980818283848586876 unmodified lines94959697989910010110210310430 unmodified lines13513613713813914014117 unmodified lines15916016116216316416580 unmodified lines246247248249250251252import jsonimport loggingimport osfrom pathlib import Pathimport requestsfrom pprint import pprintfrom schemas import UploadResult50 unmodified lineswith open(filename, "w") as f:json.dump(response_json, f, indent=2)def upload_file_to_vectara(file_bytes: bytes, filename: str) -> UploadResult:"""Uploads a supported file type to Vectara for processing.Args:file_bytes (bytes): The file content in bytes.filename (str): The name of the file.Returns:None4 unmodified lines"""CORPUS_KEY = "YouTwo" # Replace with your actual corpus key# Check if file_bytes is providedif not file_bytes:raise IndexingError("No file bytes provided.")suffix = Path(filename).suffix# Ensure valid filenameif not is_allowed_filetype(suffix):raise IndexingError("Invalid filename. Please provide a filename ending with .pdf")# Replace with your actual corpus_key and API key6 unmodified lines"Accept": "application/json","x-api-key": api_key,}files = {'file': (filename, file_bytes)}try:response = requests.post(url, headers=headers, files=files)response.raise_for_status() # Raise an exception for HTTP errors30 unmodified linesstorage_usage=response_json["storage_usage"])# See https://docs.vectara.com/docs/rest-api/query-corpusdef retrieve_chunks(query: str, limit: int = 10) -> tuple[list[str], str]:"""Retrieves relevant chunks and a generated summary from the Vectara corpus based on the query.17 unmodified linespayload = {"query": query,"search": {"limit": limit, # Number of search results to retrieve# "reranker": {# "type": "customer_reranker",# "reranker_name": "Rerank_Multilingual_v1",80 unmodified linespdf_path = Path(FILEPATH).expanduser()with open(pdf_path, "rb") as f:pdf_bytes = f.read()upload_file_to_vectara(pdf_bytes, pdf_path.name)except Exception as e:raise IndexingError(f"Error occurred while uploading PDF: {e}")
12gradio[mcp]==5.33.0python-dotenv12345gradio[mcp]==5.33.0requestspython-dotenvsmolagentsfastrtc
.gitignore+1
app.py+4-3
rag.py+15-13
requirements.txt+4-1