Spaces:
Sleeping
Sleeping
Added streamlit app
Browse files- frontend/LICENSE +0 -21
- frontend/src/assets/cube-leg.png +0 -0
- frontend/src/assets/growth.png +0 -0
- frontend/src/assets/icon.png +0 -0
- frontend/src/assets/pilot.png +0 -0
- frontend/src/assets/reflecting.png +0 -0
- frontend/src/assets/rocket-svgrepo-com.svg:Zone.Identifier +4 -0
- frontend/src/assets/rocket.svg.svg +52 -0
- frontend/src/components/Features.tsx +5 -2
- frontend/src/components/Navbar.tsx +10 -31
- frontend/src/components/upload/.streamlit/config.toml +6 -0
- frontend/src/components/upload/app-v1.py +46 -0
- frontend/src/components/upload/requirements.txt +5 -0
- frontend/src/components/upload/streamlit_app.py +47 -0
frontend/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
MIT License
|
2 |
-
|
3 |
-
Copyright (c) 2024 Leopoldo Miranda
|
4 |
-
|
5 |
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
-
of this software and associated documentation files (the "Software"), to deal
|
7 |
-
in the Software without restriction, including without limitation the rights
|
8 |
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
-
copies of the Software, and to permit persons to whom the Software is
|
10 |
-
furnished to do so, subject to the following conditions:
|
11 |
-
|
12 |
-
The above copyright notice and this permission notice shall be included in all
|
13 |
-
copies or substantial portions of the Software.
|
14 |
-
|
15 |
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
-
SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
frontend/src/assets/cube-leg.png
DELETED
Binary file (18.2 kB)
|
|
frontend/src/assets/growth.png
DELETED
Binary file (19.1 kB)
|
|
frontend/src/assets/icon.png
DELETED
Binary file (24.1 kB)
|
|
frontend/src/assets/pilot.png
DELETED
Binary file (34.7 kB)
|
|
frontend/src/assets/reflecting.png
DELETED
Binary file (19.9 kB)
|
|
frontend/src/assets/rocket-svgrepo-com.svg:Zone.Identifier
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
ReferrerUrl=https://www.svgrepo.com/svg/275999/rocket
|
4 |
+
HostUrl=https://www.svgrepo.com/download/275999/rocket.svg
|
frontend/src/assets/rocket.svg.svg
ADDED
frontend/src/components/Features.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { Badge } from "./ui/badge";
|
2 |
import {
|
3 |
Card,
|
4 |
CardTitle,
|
@@ -6,7 +6,7 @@ import {
|
|
6 |
CardHeader,
|
7 |
} from "@/components/ui/card";
|
8 |
import image4 from "../assets/looking-ahead.png";
|
9 |
-
|
10 |
|
11 |
interface FeatureProps {
|
12 |
title: string;
|
@@ -66,6 +66,9 @@ export const Features = () => {
|
|
66 |
alt="About feature"
|
67 |
className="w-[150px] lg:w-[300px] mx-auto"
|
68 |
/>
|
|
|
|
|
|
|
69 |
</CardFooter>
|
70 |
</Card>
|
71 |
))}
|
|
|
1 |
+
import { Badge } from "./ui/badge";
|
2 |
import {
|
3 |
Card,
|
4 |
CardTitle,
|
|
|
6 |
CardHeader,
|
7 |
} from "@/components/ui/card";
|
8 |
import image4 from "../assets/looking-ahead.png";
|
9 |
+
//import { Upload } from "./upload";
|
10 |
|
11 |
interface FeatureProps {
|
12 |
title: string;
|
|
|
66 |
alt="About feature"
|
67 |
className="w-[150px] lg:w-[300px] mx-auto"
|
68 |
/>
|
69 |
+
{/* Upload sections */}
|
70 |
+
|
71 |
+
|
72 |
</CardFooter>
|
73 |
</Card>
|
74 |
))}
|
frontend/src/components/Navbar.tsx
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import { useState } from "react";
|
|
|
|
|
2 |
import {
|
3 |
NavigationMenu,
|
4 |
NavigationMenuItem,
|
@@ -11,8 +13,6 @@ import {
|
|
11 |
SheetTitle,
|
12 |
SheetTrigger,
|
13 |
} from "@/components/ui/sheet";
|
14 |
-
import { GitHubLogoIcon } from "@radix-ui/react-icons";
|
15 |
-
import { buttonVariants } from "./ui/button";
|
16 |
import { Menu } from "lucide-react";
|
17 |
import { ModeToggle } from "./mode-toggle";
|
18 |
import { LogoIcon } from "./Icons";
|
@@ -73,26 +73,10 @@ export const Navbar = () => {
|
|
73 |
</SheetTitle>
|
74 |
</SheetHeader>
|
75 |
<nav className="flex flex-col justify-center items-center gap-2 mt-4">
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
onClick={() => setIsOpen(false)}
|
81 |
-
className={buttonVariants({ variant: "ghost" })}
|
82 |
-
>
|
83 |
-
{label}
|
84 |
-
</a>
|
85 |
-
))}
|
86 |
-
<a
|
87 |
-
href="#"
|
88 |
-
target="_blank"
|
89 |
-
className={`w-[110px] border ${buttonVariants({
|
90 |
-
variant: "secondary",
|
91 |
-
})}`}
|
92 |
-
>
|
93 |
-
<GitHubLogoIcon className="mr-0 w-14 h-5" />
|
94 |
-
Join Waitlist
|
95 |
-
</a>
|
96 |
</nav>
|
97 |
</SheetContent>
|
98 |
</Sheet>
|
@@ -114,15 +98,10 @@ export const Navbar = () => {
|
|
114 |
</nav>
|
115 |
|
116 |
<div className="hidden md:flex gap-2">
|
117 |
-
<a
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
>
|
122 |
-
<GitHubLogoIcon className="mr-0 w-8 h-5" />
|
123 |
-
Join Waitlist
|
124 |
-
</a>
|
125 |
-
|
126 |
<ModeToggle />
|
127 |
</div>
|
128 |
</NavigationMenuList>
|
|
|
1 |
import { useState } from "react";
|
2 |
+
import { Button } from "./ui/button";
|
3 |
+
import { buttonVariants } from "./ui/button";
|
4 |
import {
|
5 |
NavigationMenu,
|
6 |
NavigationMenuItem,
|
|
|
13 |
SheetTitle,
|
14 |
SheetTrigger,
|
15 |
} from "@/components/ui/sheet";
|
|
|
|
|
16 |
import { Menu } from "lucide-react";
|
17 |
import { ModeToggle } from "./mode-toggle";
|
18 |
import { LogoIcon } from "./Icons";
|
|
|
73 |
</SheetTitle>
|
74 |
</SheetHeader>
|
75 |
<nav className="flex flex-col justify-center items-center gap-2 mt-4">
|
76 |
+
<a>
|
77 |
+
<Button className="w-full md:w-2/3">Join Waitlist</Button>
|
78 |
+
</a>
|
79 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
</nav>
|
81 |
</SheetContent>
|
82 |
</Sheet>
|
|
|
98 |
</nav>
|
99 |
|
100 |
<div className="hidden md:flex gap-2">
|
101 |
+
<a>
|
102 |
+
<Button className="w-full ">Join Waitlist
|
103 |
+
</Button>
|
104 |
+
</a>
|
|
|
|
|
|
|
|
|
|
|
105 |
<ModeToggle />
|
106 |
</div>
|
107 |
</NavigationMenuList>
|
frontend/src/components/upload/.streamlit/config.toml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[theme]
|
2 |
+
primaryColor="#F63366"
|
3 |
+
backgroundColor="#FFFFFF"
|
4 |
+
secondaryBackgroundColor="#F0F2F6"
|
5 |
+
textColor="#262730"
|
6 |
+
font="sans serif"
|
frontend/src/components/upload/app-v1.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from langchain.llms import OpenAI
|
3 |
+
from langchain.text_splitter import CharacterTextSplitter
|
4 |
+
from langchain.embeddings import OpenAIEmbeddings
|
5 |
+
from langchain.vectorstores import Chroma
|
6 |
+
from langchain.chains import RetrievalQA
|
7 |
+
|
8 |
+
def generate_response(uploaded_file, openai_api_key, query_text):
|
9 |
+
# Load document if file is uploaded
|
10 |
+
if uploaded_file is not None:
|
11 |
+
documents = [uploaded_file.read().decode()]
|
12 |
+
# Split documents into chunks
|
13 |
+
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
14 |
+
texts = text_splitter.create_documents(documents)
|
15 |
+
# Select embeddings
|
16 |
+
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
|
17 |
+
# Create a vectorstore from documents
|
18 |
+
db = Chroma.from_documents(texts, embeddings)
|
19 |
+
# Create retriever interface
|
20 |
+
retriever = db.as_retriever()
|
21 |
+
# Create QA chain
|
22 |
+
qa = RetrievalQA.from_chain_type(llm=OpenAI(openai_api_key=openai_api_key), chain_type='stuff', retriever=retriever)
|
23 |
+
return qa.run(query_text)
|
24 |
+
|
25 |
+
# Page title
|
26 |
+
st.set_page_config(page_title='π¦π Ask the Doc App')
|
27 |
+
st.title('π¦π Ask the Doc App')
|
28 |
+
|
29 |
+
# File upload
|
30 |
+
uploaded_file = st.file_uploader('Upload an article', type='txt')
|
31 |
+
# Query text
|
32 |
+
query_text = st.text_input('Enter your question:', placeholder = 'Please provide a short summary.', disabled=not uploaded_file)
|
33 |
+
|
34 |
+
# Form input and query
|
35 |
+
result = []
|
36 |
+
with st.form('myform', clear_on_submit=True):
|
37 |
+
openai_api_key = st.text_input('OpenAI API Key', type='password', disabled=not (uploaded_file and query_text))
|
38 |
+
submitted = st.form_submit_button('Submit', disabled=not(uploaded_file and query_text))
|
39 |
+
if submitted and openai_api_key.startswith('sk-'):
|
40 |
+
with st.spinner('Calculating...'):
|
41 |
+
response = generate_response(uploaded_file, openai_api_key, query_text)
|
42 |
+
result.append(response)
|
43 |
+
del openai_api_key
|
44 |
+
|
45 |
+
if len(result):
|
46 |
+
st.info(response)
|
frontend/src/components/upload/requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
langchain
|
3 |
+
openai
|
4 |
+
chromadb
|
5 |
+
tiktoken
|
frontend/src/components/upload/streamlit_app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from langchain.llms import OpenAI
|
3 |
+
from langchain.text_splitter import CharacterTextSplitter
|
4 |
+
from langchain.embeddings import OpenAIEmbeddings
|
5 |
+
from langchain.vectorstores import Chroma
|
6 |
+
from langchain.chains import RetrievalQA
|
7 |
+
|
8 |
+
def generate_response(uploaded_file, openai_api_key, query_text):
|
9 |
+
# Load document if file is uploaded
|
10 |
+
if uploaded_file is not None:
|
11 |
+
documents = [uploaded_file.read().decode()]
|
12 |
+
# Split documents into chunks
|
13 |
+
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
14 |
+
texts = text_splitter.create_documents(documents)
|
15 |
+
# Select embeddings
|
16 |
+
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
|
17 |
+
# Create a vectorstore from documents
|
18 |
+
db = Chroma.from_documents(texts, embeddings)
|
19 |
+
# Create retriever interface
|
20 |
+
retriever = db.as_retriever()
|
21 |
+
# Create QA chain
|
22 |
+
qa = RetrievalQA.from_chain_type(llm=OpenAI(openai_api_key=openai_api_key), chain_type='stuff', retriever=retriever)
|
23 |
+
return qa.run(query_text)
|
24 |
+
|
25 |
+
|
26 |
+
# Page title
|
27 |
+
st.set_page_config(page_title='π¦π Ask the Doc App')
|
28 |
+
st.title('π¦π Ask the Doc App')
|
29 |
+
|
30 |
+
# File upload
|
31 |
+
uploaded_file = st.file_uploader('Upload an article', type='txt')
|
32 |
+
# Query text
|
33 |
+
query_text = st.text_input('Enter your question:', placeholder = 'Please provide a short summary.', disabled=not uploaded_file)
|
34 |
+
|
35 |
+
# Form input and query
|
36 |
+
result = []
|
37 |
+
with st.form('myform', clear_on_submit=True):
|
38 |
+
openai_api_key = st.text_input('OpenAI API Key', type='password', disabled=not (uploaded_file and query_text))
|
39 |
+
submitted = st.form_submit_button('Submit', disabled=not(uploaded_file and query_text))
|
40 |
+
if submitted and openai_api_key.startswith('sk-'):
|
41 |
+
with st.spinner('Calculating...'):
|
42 |
+
response = generate_response(uploaded_file, openai_api_key, query_text)
|
43 |
+
result.append(response)
|
44 |
+
del openai_api_key
|
45 |
+
|
46 |
+
if len(result):
|
47 |
+
st.info(response)
|