Ephraimmm commited on
Commit
950a339
Β·
verified Β·
1 Parent(s): 439833c

Upload 4 files

Browse files
Files changed (4) hide show
  1. RAG-1.ipynb +0 -0
  2. app.py +140 -0
  3. rag-system-463320-f292991d0516.json +13 -0
  4. requirements.txt +9 -0
RAG-1.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import GPTDriveIntegration
2
+ import gradio as gr
3
+
4
+ gpt_drive = GPTDriveIntegration()
5
+
6
+ def process_user_query(query, search_terms_input):
7
+ """Process user query and return formatted response"""
8
+ if not query.strip():
9
+ return "Please enter a question.", ""
10
+
11
+ # Parse search terms if provided
12
+ search_terms = None
13
+ # if search_terms_input.strip():
14
+ # search_terms = [term.strip() for term in search_terms_input.split(',')]
15
+
16
+ # Process the query
17
+ result = gpt_drive.process_query(query, search_terms)
18
+
19
+ # Format the response
20
+ answer = result['answer']
21
+ sources = result['sources']
22
+
23
+ sources_text = ""
24
+ if sources:
25
+ sources_text = "**Sources used:**\n" + "\n".join([f"β€’ {source}" for source in sources])
26
+
27
+ return answer, sources_text
28
+
29
+ def check_setup():
30
+ """Check if the APIs are properly configured"""
31
+ status_messages = []
32
+
33
+ # Check Google Drive API
34
+ if gpt_drive.drive_initialized:
35
+ status_messages.append("βœ… Google Drive API: Connected")
36
+ else:
37
+ status_messages.append(f"❌ Google Drive API: {getattr(gpt_drive, 'drive_error', 'Not configured')}")
38
+
39
+ # Check OpenAI API
40
+ if gpt_drive.openai_initialized:
41
+ status_messages.append("βœ… OpenAI API: Connected")
42
+ else:
43
+ status_messages.append(f"❌ OpenAI API: {getattr(gpt_drive, 'openai_error', 'Not configured')}")
44
+
45
+ return "\n".join(status_messages)
46
+
47
+ # Create Gradio interface
48
+ with gr.Blocks(title="Augusta's Anatomy Reading Assistant", theme=gr.themes.Soft()) as app:
49
+ gr.Markdown("# πŸ€– Augusta's Anatomy bot")
50
+ gr.Markdown("Ask questions about your anatomy books using AI!")
51
+
52
+ with gr.Row():
53
+ with gr.Column(scale=2):
54
+ # Main query interface
55
+ with gr.Group():
56
+ gr.Markdown("### Ask a Question")
57
+ query_input = gr.Textbox(
58
+ label="Your Question",
59
+ placeholder="Ask me any question about your anatomy books?",
60
+ lines=3
61
+ )
62
+
63
+ search_terms_input = gr.Textbox(
64
+ label="Search Terms (optional)",
65
+ placeholder="Enter comma-separated terms to search for specific files",
66
+ lines=1
67
+ )
68
+
69
+ submit_btn = gr.Button("Search & Ask", variant="primary", size="lg")
70
+
71
+ # Results section
72
+ with gr.Group():
73
+ gr.Markdown("### Answer")
74
+ answer_output = gr.Textbox(
75
+ label="AI Response",
76
+ lines=10,
77
+ interactive=False
78
+ )
79
+
80
+ sources_output = gr.Textbox(
81
+ label="Sources",
82
+ lines=3,
83
+ interactive=False
84
+ )
85
+
86
+ with gr.Column(scale=1):
87
+ # Status and setup info
88
+ with gr.Group():
89
+ gr.Markdown("### System Status")
90
+ status_btn = gr.Button("Check Status", size="sm")
91
+ status_output = gr.Textbox(
92
+ label="API Status",
93
+ lines=4,
94
+ interactive=False
95
+ )
96
+
97
+ with gr.Group():
98
+ gr.Markdown("### Setup Instructions")
99
+ gr.Markdown("""
100
+ **Important Notes:**
101
+ 1.Only documents shared with it, it can answer
102
+
103
+ **File Types Supported:**
104
+ - Google Docs
105
+ - Google Sheets
106
+ - PDF files
107
+ - Text files
108
+
109
+ **Tips:**
110
+ - Use specific search terms for better results
111
+ - The system searches the top 3 most relevant files
112
+ - Ask clear, specific questions for better answers
113
+ """)
114
+
115
+ # Event handlers
116
+ submit_btn.click(
117
+ fn=process_user_query,
118
+ inputs=[query_input, search_terms_input],
119
+ outputs=[answer_output, sources_output]
120
+ )
121
+
122
+ status_btn.click(
123
+ fn=check_setup,
124
+ outputs=status_output
125
+ )
126
+
127
+ # Example queries
128
+ with gr.Row():
129
+ gr.Examples(
130
+ examples=[
131
+ ["What is morbid Anatomy?", "morbid, Anatomy"],
132
+ ["The transmission of nerves from one neuron to another is as a result of what?", "neuron, nerves, Dr Clement"],
133
+ ],
134
+ inputs=[query_input, search_terms_input],
135
+ )
136
+
137
+ # Launch the app
138
+ if __name__ == "__main__":
139
+ app.launch(
140
+ share=True,debug =True)
rag-system-463320-f292991d0516.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "service_account",
3
+ "project_id": "rag-system-463320",
4
+ "private_key_id": "f292991d051639790555548b3142cf9447594bee",
5
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCaIHHexQcwmlEx\n/68EK7q8RGtLGVVubssDFzw9eiCjBh71PNhpaXBj0RiwKtnmCrfuYZ0RHm1OQN1l\niiXE7eiRuDkgmhfuLx4k8+L7tBfEcpVA9HHEZXKpp1YHUnuDsS4UZWZDlc/Q/O6q\njt5xwcKpnDMYsOTVXSuj6NslzVmYQYgW3xAastKUzAr3N/zXnH4rvnCS9N2QocC7\nZ8Z+dQYLd4QG2Pty7Oe/FVCdPWM9HfT9MmdBDeJfxran3Wni+TXBqH9NWJsMVnAl\nLkix6iFuBGaGBKQwEmX5GwN59ILb26U8hcOgwrbVVqZS4CKEH4sodcDlsf6iPXbr\nJVGeBLUZAgMBAAECggEAAOK89MfS9rKX4TCCO+ifwbNSSWkjeEPTSEcZEj7s66Sw\nFWlAC5DO08+ShVvBrngE91irepBRC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0/Zejb\nptZwejr3WB+6GwYWkabRxosVhsKBtaT/8NMmPtwZ1jEukZW4UbIAOziJ8OM/mhfm\ns3CDpUHWETb1X9bB3Jwljoc=\n-----END PRIVATE KEY-----\n",
6
+ "client_email": "rag-base@rag-system-463320.iam.gserviceaccount.com",
7
+ "client_id": "110051039758068935524",
8
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
+ "token_uri": "https://oauth2.googleapis.com/token",
10
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/rag-base%40rag-system-463320.iam.gserviceaccount.com",
12
+ "universe_domain": "googleapis.com"
13
+ }
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ google-api-python-client
2
+ google-auth
3
+ openai
4
+ python-dotenv
5
+ chromadb
6
+ sentence-transformers
7
+ numpy
8
+ gradio
9
+ flask