vishanth10 commited on
Commit
12eeed0
·
1 Parent(s): 53bfeb0

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +84 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from decimal import Decimal
3
+ from carbon import Carbon
4
+ import requests
5
+ import json
6
+
7
+ # Carbon API Key
8
+ CARBON_API_KEY = "a38ee1fe5fef56fc8e1ae2afc881378804bb902882442e1554adae4f82ee23ea"
9
+ customer_id = "Candid"
10
+
11
+ # Define your main function here
12
+ def main():
13
+ st.title('Google Drive Data Connector using Carbon SDK')
14
+
15
+ st.write('### Authenticate with Carbon API')
16
+ carbon = Carbon(api_key=CARBON_API_KEY, customer_id=customer_id)
17
+ token = carbon.auth.get_access_token()
18
+ carbon = Carbon(access_token=token.access_token) # authenticated object
19
+
20
+ st.write('### Connect to Google Drive')
21
+ get_oauth_url_response = carbon.integrations.get_oauth_url(
22
+ service="GOOGLE_DRIVE",
23
+ tags=None,
24
+ scope="string_example",
25
+ chunk_size=Decimal(1500),
26
+ chunk_overlap=Decimal(15),
27
+ skip_embedding_generation=False,
28
+ embedding_model="OPENAI",
29
+ generate_sparse_vectors=False,
30
+ prepend_filename_to_chunks=False,
31
+ max_items_per_chunk=Decimal(1),
32
+ salesforce_domain="string_example",
33
+ sync_files_on_connection=True,
34
+ set_page_as_boundary=False,
35
+ data_source_id=Decimal(1),
36
+ connecting_new_account=False,
37
+ request_id="b7620173-662c-4ae7-bb61-2e6ffd8619f5",
38
+ use_ocr=False,
39
+ parse_pdf_tables_with_ocr=False,
40
+ enable_file_picker=True,
41
+ sync_source_items=True,
42
+ incremental_sync=False,
43
+ file_sync_config={
44
+ "auto_synced_source_types": ["ARTICLE"],
45
+ "sync_attachments": False,
46
+ "detect_audio_language": False,
47
+ },
48
+ )
49
+
50
+ st.write(f"OAuth URL: {get_oauth_url_response.oauth_url}")
51
+
52
+ st.write('### Search in the Connected Data Source')
53
+ query = st.text_input("Enter your query:", value="Is there a web version of CNN explainer?")
54
+ if query:
55
+ url = "https://api.carbon.ai/embeddings"
56
+ payload = {
57
+ "query": query,
58
+ "k": 2,
59
+ "file_ids": [1], # Dummy file_id for demonstration
60
+ "include_all_children": True,
61
+ "tags": {},
62
+ "include_tags": True,
63
+ "include_vectors": True,
64
+ "include_raw_file": True,
65
+ "hybrid_search": False,
66
+ "media_type": "TEXT",
67
+ "embedding_model": "OPENAI"
68
+ }
69
+ headers = {
70
+ "authorization": f"Bearer {CARBON_API_KEY}",
71
+ "customer-id": customer_id,
72
+ "Content-Type": "application/json"
73
+ }
74
+ response_search = requests.post(url, json=payload, headers=headers)
75
+ response_search_chunks = json.loads(response_search.text)
76
+
77
+ for i, doc in enumerate(response_search_chunks['documents']):
78
+ st.write(f"Document {i+1}")
79
+ st.write(doc['content'])
80
+ st.write("-------------------------------------------------")
81
+
82
+ # Call the main function
83
+ if __name__ == '__main__':
84
+ main()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ carbon-python-sdk
3
+ requests