Spaces:
Sleeping
Sleeping
File size: 2,029 Bytes
1d39232 4137b5b 3b5cb60 5c7d5dc 4137b5b e1f6414 6d55f94 5c7d5dc 1d39232 3b5cb60 c5dfe2a 6d55f94 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import os
import streamlit as st
from langchain_community.graphs import Neo4jGraph
from langchain_groq import ChatGroq
from langchain.chains import GraphCypherQAChain
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Set environment variables
NEO4J_URI = "neo4j+s://64beefae.databases.neo4j.io"
NEO4J_USERNAME = "neo4j"
NEO4J_PASSWORD = "OTj5yGnWLF59yx4UX1g3xABarVOvVKiM3CT9L4bNkF8"
groq_api_key = os.getenv("GROQ_API_KEY")
GROQ_API_KEY = "groq_api_key"
# Print environment variables for debugging
print("NEO4J_URI:", NEO4J_URI)
print("NEO4J_USERNAME:", NEO4J_USERNAME)
print("NEO4J_PASSWORD:", NEO4J_PASSWORD)
try:
# Initialize Neo4j graph
graph = Neo4jGraph(url=NEO4J_URI, username=NEO4J_USERNAME, password=NEO4J_PASSWORD)
# Load movie dataset into Neo4j
moview_query = """
LOAD CSV WITH HEADERS FROM
'https://raw.githubusercontent.com/Pk-Kolhapurkar/graphdb_neo4j/main/indian%20movies.csv' AS row
MERGE (m:Movie {id: row.ID})
SET m.year = toInteger(row.Year),
m.title = row['Movie Name'],
m.timing = toInteger(row['Timing(min)']),
m.rating = toFloat(row['Rating(10)']),
m.votes = toInteger(row.Votes),
m.language = row.Language
FOREACH (genre IN split(row.Genre, '|') |
MERGE (g:Genre {name: trim(genre)})
MERGE (m)-[:IN_GENRE]->(g))
"""
graph.query(moview_query)
graph.refresh_schema()
except Exception as e:
print("Error initializing Neo4jGraph:", str(e))
# Initialize LLM
llm = ChatGroq(groq_api_key=GROQ_API_KEY, model_name="Gemma2-9b-It")
# Create QA Chain
chain = GraphCypherQAChain.from_llm(graph=graph, llm=llm, verbose=True)
# Streamlit UI
st.title("Movie Director Finder")
query = st.text_input("Enter your query:", "Who was the director of the movie Casino")
if st.button("Find Director"):
response = chain.invoke({"query": query})
if response and response.get("result"):
st.write(response["result"])
else:
st.write("I don't know the answer.")
|