anen commited on
Commit
de1df0d
1 Parent(s): cf11299

Upload 3 files

Browse files
Files changed (3) hide show
  1. aifunc.py +46 -0
  2. main.py +34 -0
  3. sapmle.txt +6 -0
aifunc.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import keyboard
3
+ import time
4
+ import requests
5
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = "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"
6
+ #from langchain.vectorstores.weaviate import Weaviate
7
+ from langchain.document_loaders import TextLoader #for textfiles
8
+ from langchain.text_splitter import CharacterTextSplitter #text splitter
9
+ from langchain.embeddings import HuggingFaceEmbeddings #for using HugginFace models
10
+ # Vectorstore: https://python.langchain.com/en/latest/modules/indexes/vectorstores.html
11
+ from langchain.vectorstores import FAISS #facebook vectorizationfrom langchain.chains.question_answering import load_qa_chain
12
+ from langchain.chains.question_answering import load_qa_chain
13
+ from langchain import HuggingFaceHub
14
+ from langchain.document_loaders import UnstructuredPDFLoader #load pdf
15
+ from langchain.indexes import VectorstoreIndexCreator #vectorize db index with chromadb
16
+ from langchain.chains import RetrievalQA
17
+ from langchain.document_loaders import UnstructuredURLLoader #load urls into docoument-loader
18
+ import requests
19
+ import textwrap
20
+ from langchain.document_loaders import TextLoader
21
+
22
+ loader = TextLoader('./KS-all-info_rev1.txt')
23
+ documents = loader.load()
24
+ def wrap_text_preserve_newlines(text, width=110):
25
+ # Split the input text into lines based on newline characters
26
+ lines = text.split('\n')
27
+ # Wrap each line individually
28
+ wrapped_lines = [textwrap.fill(line, width=width) for line in lines]
29
+ # Join the wrapped lines back together using newline characters
30
+ wrapped_text = '\n'.join(wrapped_lines)
31
+ return wrapped_text
32
+ text_splitter = CharacterTextSplitter(chunk_size=3000, chunk_overlap=10)
33
+ docs = text_splitter.split_documents(documents)
34
+ # Embeddings
35
+ embeddings = HuggingFaceEmbeddings()
36
+ #Create the vectorized db
37
+ # Vectorstore: https://python.langchain.com/en/latest/modules/indexes/vectorstores.html
38
+ db = FAISS.from_documents(docs, embeddings)
39
+ llm=HuggingFaceHub(repo_id="MBZUAI/LaMini-Flan-T5-783M", model_kwargs={"temperature":0, "max_length":512})
40
+ chain = load_qa_chain(llm, chain_type="stuff")
41
+ def run_chain(query):
42
+ result=chain.run(input_documents=docs, question=query)
43
+ return result
44
+
45
+
46
+ #keyboard.unhook_all()###########################
main.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from aifunc import run_chain
3
+
4
+ def main():
5
+ st.title("DentalGPT For Everybody")
6
+
7
+ # File upload window
8
+ uploaded_file = st.file_uploader("Upload files to ML")
9
+
10
+ # Text input window
11
+ user_input = st.text_input("Enter text")
12
+
13
+ # Process uploaded file and user input
14
+ result = process_data(uploaded_file, user_input)
15
+
16
+ # Display result in a read-only text field
17
+ st.text_area("Result", value=result, disabled=True)
18
+
19
+ def process_data(file, input_text):
20
+ # Perform data processing here based on the uploaded file and user input
21
+ # Return the processed result as a string
22
+ # Example implementation:
23
+ if file is not None:
24
+ file_contents = file.read()
25
+ # Process file contents
26
+
27
+ # Process user input
28
+ # ...
29
+
30
+ # Return the result
31
+ return "Processed result"
32
+
33
+ if __name__ == '__main__':
34
+ main()
sapmle.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ In his follow-up to 'Symbiosis',Sterling takes a look at the subtle, unnoticed presence and influence of AI in our everyday lives.
2
+ It reveals how AI has become woven into our routines, often without our explicit realization.Dr. Cortez takes readers on a journey exploring the controversial topic of AI consciousness.
3
+ The book provides compelling arguments for and against the possibility of true AI sentience.In her second book, Dr. Simmons delves deeper into the ethical considerations surrounding AI development and deployment.
4
+ It is an eye-opening examination of the dilemmas faced by developers, policymakers, and society at large.Sterling explores the potential for harmonious coexistence between humans and artificial intelligence.
5
+ The book discusses how AI can be integrated into society in a beneficial and non-disruptive manner.A comprehensive analysis of the evolution of artificial intelligence, from its inception to its future prospects.
6
+ Dr. Simmons covers ethical considerations, potentials, and threats posed by AI.