Spaces:
Runtime error
Runtime error
tensorgirl
commited on
Upload 7 files
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.document_loaders import DirectoryLoader
|
2 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
3 |
+
from langchain.embeddings import SentenceTransformerEmbeddings
|
4 |
+
from langchain.vectorstores import Chroma
|
5 |
+
from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
|
6 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
7 |
+
from langchain.chains.question_answering import load_qa_chain
|
8 |
+
import gradio as gr
|
9 |
+
import torch
|
10 |
+
from huggingface_hub import login
|
11 |
+
import os
|
12 |
+
|
13 |
+
directory = 'pets'
|
14 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
15 |
+
login(token = HF_TOKEN)
|
16 |
+
|
17 |
+
def load_docs(directory):
|
18 |
+
loader = DirectoryLoader(directory)
|
19 |
+
documents = loader.load()
|
20 |
+
return documents
|
21 |
+
|
22 |
+
def split_docs(documents,chunk_size=1000,chunk_overlap=20):
|
23 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap)
|
24 |
+
docs = text_splitter.split_documents(documents)
|
25 |
+
return docs
|
26 |
+
|
27 |
+
documents = load_docs(directory)
|
28 |
+
docs = split_docs(documents)
|
29 |
+
embeddings = SentenceTransformerEmbeddings(model_name="thenlper/gte-large")
|
30 |
+
|
31 |
+
db = Chroma.from_documents(docs, embeddings)
|
32 |
+
|
33 |
+
model_id = "google/gemma-1.1-2b-it"
|
34 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
35 |
+
model = AutoModelForCausalLM.from_pretrained(model_id,torch_dtype=torch.bfloat16)
|
36 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=100)
|
37 |
+
hf = HuggingFacePipeline(pipeline=pipe)
|
38 |
+
|
39 |
+
chain = load_qa_chain(hf, chain_type="stuff",verbose=True)
|
40 |
+
|
41 |
+
def output(query, history):
|
42 |
+
|
43 |
+
matching_docs = db.similarity_search(query)
|
44 |
+
answer = chain.run(input_documents=matching_docs, question=query)
|
45 |
+
idx = answer.find("Answer")
|
46 |
+
|
47 |
+
return answer[idx:]
|
48 |
+
|
49 |
+
|
50 |
+
gr.ChatInterface(output).launch()
|
pets/Different Types of Pet Animals.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Pet animals come in all shapes and sizes, each suited to different lifestyles and home environments. Dogs and cats are the most common, known for their companionship and unique personalities. Small mammals like hamsters, guinea pigs, and rabbits are often chosen for their low maintenance needs. Birds offer beauty and song, and reptiles like turtles and lizards can make intriguing pets. Even fish, with their calming presence, can be wonderful pets.
|
pets/Health Care for Pets.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Routine health care is crucial for pets to live long, happy lives. Regular vet check-ups help catch potential issues early and keep vaccinations up to date. Dental care is also essential to prevent diseases in pets, especially in dogs and cats. Regular grooming, parasite control, and weight management are other important aspects of pet health care.
|
pets/Nutrition Needs of Pet Animals.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Proper nutrition is vital for the health and wellbeing of pets. Dogs and cats require a balanced diet that includes proteins, carbohydrates, and fats. Some may even have specific dietary needs based on their breed or age. Birds typically thrive on a diet of seeds, fruits, and vegetables, while reptiles have diverse diets ranging from live insects to fresh produce. Fish diets depend greatly on the species, with some needing live food and others subsisting on flakes or pellets.
|
pets/The Emotional Bond Between Humans and Pets.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Pets offer more than just companionship; they provide emotional support, reduce stress, and can even help their owners lead healthier lives. The bond between pets and their owners is strong, and many people consider their pets as part of the family. This bond can be especially important in times of personal or societal stress, providing comfort and consistency.
|
pets/Training and Behaviour of Pets.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Training is essential for a harmonious life with pets, particularly for dogs. It helps pets understand their boundaries and makes cohabitation easier for both pets and owners. Training should be based on positive reinforcement. Understanding pet behavior is also important, as changes in behavior can often be a sign of underlying health issues.
|
requirements.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain
|
2 |
+
transformers
|
3 |
+
chroma
|
4 |
+
datasets
|
5 |
+
pandas
|
6 |
+
chromadb
|
7 |
+
sentence_transformers
|
8 |
+
transformers
|
9 |
+
accelerate
|
10 |
+
unstructured
|