Ephraimmm commited on
Commit
ef70a1e
Β·
verified Β·
1 Parent(s): 4a19a85

Delete appi.py

Browse files
Files changed (1) hide show
  1. appi.py +0 -140
appi.py DELETED
@@ -1,140 +0,0 @@
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)