Skip to content

Commit

Permalink
adding the model
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramyrahmeni committed Jun 15, 2024
1 parent d8497b8 commit efed2b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
API_KEY="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"
API_KEY="AIzaSyDKEHq4T8Iiqq9ywPaWFMBkxzJbPIKkx6s"
23 changes: 13 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import re
from sentence_transformers import SentenceTransformer, util
from transformers import AutoTokenizer, AutoModelForCausalLM , pipeline

import os
from stqdm import stqdm
import torch
import textwrap
from dotenv import load_dotenv
import os
def configure():
load_dotenv()
import google.generativeai as gen_ai
load_dotenv()
GOOGLE_API_KEY = os.getenv("API_KEY")

gen_ai.configure(api_key=GOOGLE_API_KEY)
model = gen_ai.GenerativeModel('gemini-pro')
def prompt_formatter(query: str,
context_items: list[dict],tokenizer) -> str:
"""
Expand Down Expand Up @@ -272,15 +275,15 @@ def ask(query, model, embedding_model, embeddings, pages_and_chunks, tokenizer,
''')

def main():
configure()

st.header("Chat with PDF 💬")

MAX_UPLOAD_SIZE_MB = 30
MAX_UPLOAD_SIZE_BYTES = MAX_UPLOAD_SIZE_MB * 1024 * 1024

pdf = st.file_uploader(f"Upload your PDF (Limit {MAX_UPLOAD_SIZE_MB}MB per file)", type='pdf')
query = st.text_input("Ask questions about your PDF file:")

st.text(model)
if pdf:
if pdf.size > MAX_UPLOAD_SIZE_BYTES:
st.error(f"File size is too large! Please upload a file smaller than {MAX_UPLOAD_SIZE_MB} MB.")
Expand Down Expand Up @@ -319,19 +322,19 @@ def main():
'''print_top_results_and_scores(query=query,pages_and_chunks=pages_and_chunks,embedding_model=embedding_model,
embeddings=embeddings)'''
#importing the model
model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3-mini-4k-instruct",
'''model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3-mini-4k-instruct",
device_map="cpu",
torch_dtype="auto",
trust_remote_code=True,
token='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'
)
print(model)
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct",token='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')
ask(query,model,embedding_model,embeddings,pages_and_chunks,tokenizer,
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct",token='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')'''
'''ask(query,model,embedding_model,embeddings,pages_and_chunks,tokenizer,
temperature=0.7,
max_new_tokens=512,
format_answer_text=True,
return_answer_only=True)
return_answer_only=True)'''
#st.text(answer)

if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ streamlit==1.30.0
sentence_transformers
torch
stqdm
accelerate
accelerate
google-generativeai==0.3.2

0 comments on commit efed2b5

Please sign in to comment.