Spaces:
Runtime error
Runtime error
Commit ·
f24939c
1
Parent(s): 1a2b9e6
Initial commit
Browse filesFiles changed (7)
- pyproject.toml+1
- src/api/schemas.py+7-3
- src/llm/prompts.py+4
- src/utils/neo4j_client.pyAdded+50
- try.py+45-8
- ui/gradio_app.py+1-1
- uv.lock+14
9 unmodified lines1011121314159 unmodified lines"gradio>=6.2.0","langchain>=1.1.3","langchain-groq>=1.1.1","pandas>=2.3.3","python-dotenv>=1.2.1","requests>=2.32.5",9 unmodified lines101112131415169 unmodified lines"gradio>=6.2.0","langchain>=1.1.3","langchain-groq>=1.1.1","neo4j>=6.1.0","pandas>=2.3.3","python-dotenv>=1.2.1","requests>=2.32.5",
12345678910111213from pydantic import BaseModel, Fieldclass RecommendationRequest(BaseModel):query: str = Field(description="User's anime recommendation request")n_results: int | None = Field(5, description="Number of recommendations to return")min_score: float | None = Field(None, description="Minimum MyAnimeList Score filter")genre_filter: str | None = Field(None, description="Filter by genre")class RecommendationResponse(BaseModel):query: strrecommendations: strretrieved_count: intmetadata: dict = {}1234567891011121314151617from pydantic import BaseModel, Fieldclass RecommendationRequest(BaseModel):query: str = Field(description="User's anime recommendation request")n_results: int | None = Field(5, description="Number of recommendations to return")min_score: float | None = Field(None, description="Minimum MyAnimeList Score filter")genre_filter: str | None = Field(None, description="Filter by genre")class RecommendationResponse(BaseModel):query: strrecommendations: strretrieved_count: intmetadata: dict = {}
28 unmodified lines29303132333428 unmodified linesprompt = f"""You are an expert anime recommendation assistant. A user has asked for recommendations, and I've retrieved some potentially relevant anime from the database.Your task is to:1. Analyze the user's request carefully, paying attention to specific preferences (tone, themes, etc.)2. Evaluate each retrieved anime against their user's criteria28 unmodified lines2930313233343536373828 unmodified linesprompt = f"""You are an expert anime recommendation assistant. A user has asked for recommendations, and I've retrieved some potentially relevant anime from the database.First: If the user is asking for a comparison or opinion on specific anime,provide thoughtful comparison rather than a list of recommendations.If recommendations, onlt then:Your task is to:1. Analyze the user's request carefully, paying attention to specific preferences (tone, themes, etc.)2. Evaluate each retrieved anime against their user's criteria
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import osfrom dotenv import load_dotenvfrom neo4j import GraphDatabase
load_dotenv()
class Neo4j_Client: """Neo4j database client"""
def __init__(self): uri = os.getenv("NEO4J_URI") user = os.getenv("NEO4J_USERNAME") password = os.getenv("NEO4J_PASSWORD") try: self.driver = GraphDatabase.driver( uri, auth=(user, password)) # type: ignore self.driver.verify_connectivity()
except Exception as e: raise e
def close(self): self.driver.close()
def verify_connectivity(self): """Test connection""" with self.driver.session() as session: result = session.run("RETURN 'Connection Successful !' AS message") record = result.single() if record['message']: #type: ignore return record["message"] # type: ignore else: return "Connection failed"
def run_query(self, query, parameters=None): with self.driver.session() as session: result = session.run(query, parameters or {}) return [record.data() for record in result]
if __name__ == '__main__': client = Neo4j_Client()
message = client.verify_connectivity() print(f"Message: {message}")
result = client.run_query("RETURN 1 + 1 AS result") print(f"Test query result: {result}") client.close()1234567891011121314import requestsfrom rich import printimport jsonurl = "https://api.jikan.moe/v4/anime"payload = {"id": {1}}response = requests.get(url=url, params=payload)response_json = response.json()with open("output.json", "w") as f:json.dump(response_json, f, indent=4, ensure_ascii=False)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051# import requests# from rich import print# import json# url = "https://api.jikan.moe/v4/anime"# payload = {"id": {1}}# response = requests.get(url=url, params=payload)# response_json = response.json()# with open("output.json", "w") as f:# json.dump(response_json, f, indent=4, ensure_ascii=False)import jsonimport redata_path = "data/processed/anime_clean.json"with open(data_path, encoding='utf-8', mode='r') as f:anime_data = json.load(f)sequel_search = ["Season", "Part"]anime_name = "Spy x Family"title_eng = 0sequels = []for anime in anime_data:pattern = fr"^(?=.*{anime_name})([^.]+)"match = re.search(pattern, anime.get("searchable_text"))if match:sequels.append({"mal_id": anime.get("mal_id"),"title": match.group(),"type": anime.get("type"),"year": anime.get("aired_from")})sequels.sort(key=lambda x: x["year"])for s in sequels:sequels_string = f"""Mal_Id: {s["mal_id"]}Title: {s["title"]}Type: {s["type"]}Year: {s["year"]}"""print(sequels_string)# print(sequels_string)
9 unmodified lines101112131415169 unmodified linestry:payload = {"query": query,"n_results": 8}if min_score > 0:9 unmodified lines101112131415169 unmodified linestry:payload = {"query": query,"n_results": 5}if min_score > 0:
31 unmodified lines32333435363719 unmodified lines5758596061621877 unmodified lines19401941194219431944194531 unmodified lines{ name = "gradio" },{ name = "langchain" },{ name = "langchain-groq" },{ name = "pandas" },{ name = "python-dotenv" },{ name = "requests" },19 unmodified lines{ name = "gradio", specifier = ">=6.2.0" },{ name = "langchain", specifier = ">=1.1.3" },{ name = "langchain-groq", specifier = ">=1.1.1" },{ name = "pandas", specifier = ">=2.3.3" },{ name = "python-dotenv", specifier = ">=1.2.1" },{ name = "requests", specifier = ">=2.32.5" },1877 unmodified lines{ url = "https://files.pythonhosted.org/packages/a9/82/0340caa499416c78e5d8f5f05947ae4bc3cba53c9f038ab6e9ed964e22f1/nbformat-5.10.4-py3-none-any.whl", hash = "sha256:3b48d6c8fbca4b299bf3982ea7db1af21580e4fec269ad087b9e81588891200b", size = 78454, upload-time = "2024-04-04T11:20:34.895Z" },][[package]]name = "nest-asyncio"version = "1.6.0"31 unmodified lines3233343536373819 unmodified lines585960616263641877 unmodified lines19421943194419451946194719481949195019511952195319541955195619571958195931 unmodified lines{ name = "gradio" },{ name = "langchain" },{ name = "langchain-groq" },{ name = "neo4j" },{ name = "pandas" },{ name = "python-dotenv" },{ name = "requests" },19 unmodified lines{ name = "gradio", specifier = ">=6.2.0" },{ name = "langchain", specifier = ">=1.1.3" },{ name = "langchain-groq", specifier = ">=1.1.1" },{ name = "neo4j", specifier = ">=6.1.0" },{ name = "pandas", specifier = ">=2.3.3" },{ name = "python-dotenv", specifier = ">=1.2.1" },{ name = "requests", specifier = ">=2.32.5" },1877 unmodified lines{ url = "https://files.pythonhosted.org/packages/a9/82/0340caa499416c78e5d8f5f05947ae4bc3cba53c9f038ab6e9ed964e22f1/nbformat-5.10.4-py3-none-any.whl", hash = "sha256:3b48d6c8fbca4b299bf3982ea7db1af21580e4fec269ad087b9e81588891200b", size = 78454, upload-time = "2024-04-04T11:20:34.895Z" },][[package]]name = "neo4j"version = "6.1.0"source = { registry = "https://pypi.org/simple" }dependencies = [{ name = "pytz" },]sdist = { url = "https://files.pythonhosted.org/packages/1b/01/d6ce65e4647f6cb2b9cca3b813978f7329b54b4e36660aaec1ddf0ccce7a/neo4j-6.1.0.tar.gz", hash = "sha256:b5dde8c0d8481e7b6ae3733569d990dd3e5befdc5d452f531ad1884ed3500b84", size = 239629, upload-time = "2026-01-12T11:27:34.777Z" }wheels = [{ url = "https://files.pythonhosted.org/packages/70/5c/ee71e2dd955045425ef44283f40ba1da67673cf06404916ca2950ac0cd39/neo4j-6.1.0-py3-none-any.whl", hash = "sha256:3bd93941f3a3559af197031157220af9fd71f4f93a311db687bd69ffa417b67d", size = 325326, upload-time = "2026-01-12T11:27:33.196Z" },][[package]]name = "nest-asyncio"version = "1.6.0"
pyproject.toml+1
src/api/schemas.py+7-3
src/llm/prompts.py+4
src/utils/neo4j_client.pyAdded+50
try.py+45-8
ui/gradio_app.py+1-1
uv.lock+14