Spaces:
Sleeping
Sleeping
Commit
Β·
f776487
1
Parent(s):
897ec15
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,10 @@ import streamlit as st
|
|
2 |
from dotenv import load_dotenv
|
3 |
from PyPDF2 import PdfReader
|
4 |
from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter
|
|
|
5 |
from langchain.embeddings import OpenAIEmbeddings, HuggingFaceInstructEmbeddings
|
|
|
|
|
6 |
from langchain.vectorstores import FAISS, Chroma
|
7 |
from langchain.embeddings import HuggingFaceEmbeddings # General embeddings from HuggingFace models.
|
8 |
from langchain.chat_models import ChatOpenAI
|
@@ -60,22 +63,30 @@ def get_vectorstore(text_chunks):
|
|
60 |
|
61 |
return vectorstore # μμ±λ λ²‘ν° μ€ν μ΄λ₯Ό λ°νν©λλ€.
|
62 |
|
63 |
-
|
64 |
def get_conversation_chain(vectorstore):
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
# λν κΈ°λ‘μ μ μ₯νκΈ° μν λ©λͺ¨λ¦¬λ₯Ό μμ±ν©λλ€.
|
69 |
memory = ConversationBufferMemory(
|
70 |
memory_key='chat_history', return_messages=True)
|
|
|
71 |
# λν κ²μ 체μΈμ μμ±ν©λλ€.
|
72 |
conversation_chain = ConversationalRetrievalChain.from_llm(
|
73 |
-
llm=
|
74 |
retriever=vectorstore.as_retriever(),
|
75 |
memory=memory
|
76 |
)
|
|
|
77 |
return conversation_chain
|
78 |
|
|
|
79 |
# μ¬μ©μ μ
λ ₯μ μ²λ¦¬νλ ν¨μμ
λλ€.
|
80 |
def handle_userinput(user_question):
|
81 |
# λν 체μΈμ μ¬μ©νμ¬ μ¬μ©μ μ§λ¬Έμ λν μλ΅μ μμ±ν©λλ€.
|
|
|
2 |
from dotenv import load_dotenv
|
3 |
from PyPDF2 import PdfReader
|
4 |
from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter
|
5 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
6 |
from langchain.embeddings import OpenAIEmbeddings, HuggingFaceInstructEmbeddings
|
7 |
+
from peft import PeftModel, PeftConfig
|
8 |
+
from transformers import AutoModelForCausalLM
|
9 |
from langchain.vectorstores import FAISS, Chroma
|
10 |
from langchain.embeddings import HuggingFaceEmbeddings # General embeddings from HuggingFace models.
|
11 |
from langchain.chat_models import ChatOpenAI
|
|
|
63 |
|
64 |
return vectorstore # μμ±λ λ²‘ν° μ€ν μ΄λ₯Ό λ°νν©λλ€.
|
65 |
|
|
|
66 |
def get_conversation_chain(vectorstore):
|
67 |
+
# Replace 'microsoft/DialoGPT-large' with the desired model name
|
68 |
+
model_name = "Shaleen123/mistrallite_medical_qa"
|
69 |
+
|
70 |
+
config = PeftConfig.from_pretrained(model_name)
|
71 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
72 |
+
model = PeftModel.from_pretrained(model, model_name)
|
73 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
74 |
+
|
75 |
|
76 |
# λν κΈ°λ‘μ μ μ₯νκΈ° μν λ©λͺ¨λ¦¬λ₯Ό μμ±ν©λλ€.
|
77 |
memory = ConversationBufferMemory(
|
78 |
memory_key='chat_history', return_messages=True)
|
79 |
+
|
80 |
# λν κ²μ 체μΈμ μμ±ν©λλ€.
|
81 |
conversation_chain = ConversationalRetrievalChain.from_llm(
|
82 |
+
llm=model,
|
83 |
retriever=vectorstore.as_retriever(),
|
84 |
memory=memory
|
85 |
)
|
86 |
+
|
87 |
return conversation_chain
|
88 |
|
89 |
+
|
90 |
# μ¬μ©μ μ
λ ₯μ μ²λ¦¬νλ ν¨μμ
λλ€.
|
91 |
def handle_userinput(user_question):
|
92 |
# λν 체μΈμ μ¬μ©νμ¬ μ¬μ©μ μ§λ¬Έμ λν μλ΅μ μμ±ν©λλ€.
|