Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,10 @@ import asyncio
|
|
6 |
import gradio as gr
|
7 |
import requests
|
8 |
import os
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Define environment variables
|
11 |
API_URL = os.getenv("API_URL", "http://ec2-54-166-81-166.compute-1.amazonaws.com:3000/api/v1/prediction/117a5076-c05e-4208-91d9-d0e772bf981e")
|
@@ -24,14 +28,21 @@ class ChatBot:
|
|
24 |
# Make an external API call
|
25 |
headers = {"Authorization": API_TOKEN}
|
26 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
|
|
|
|
|
|
|
27 |
if response.status_code == 200:
|
28 |
-
|
29 |
-
else:
|
30 |
-
chat_history_ids = {"response": "Error in API call"}
|
31 |
|
32 |
# Process the API response and update history
|
33 |
-
self.history.append(
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
35 |
return response_text
|
36 |
|
37 |
bot = ChatBot()
|
@@ -50,6 +61,7 @@ iface = gr.Interface(
|
|
50 |
|
51 |
iface.launch()
|
52 |
|
|
|
53 |
class KnowledgeBaseExample(KnowledgeBase):
|
54 |
def perform_semantic_search(self, query_text: str, desired_number_of_results: int) -> List[SemanticSearchResult]:
|
55 |
result_example = SemanticSearchResult(
|
@@ -79,4 +91,4 @@ if __name__ == '__main__':
|
|
79 |
],
|
80 |
port=5000
|
81 |
)
|
82 |
-
server.run()
|
|
|
6 |
import gradio as gr
|
7 |
import requests
|
8 |
import os
|
9 |
+
import logging
|
10 |
+
|
11 |
+
# Configure logging
|
12 |
+
logging.basicConfig(level=logging.DEBUG)
|
13 |
|
14 |
# Define environment variables
|
15 |
API_URL = os.getenv("API_URL", "http://ec2-54-166-81-166.compute-1.amazonaws.com:3000/api/v1/prediction/117a5076-c05e-4208-91d9-d0e772bf981e")
|
|
|
28 |
# Make an external API call
|
29 |
headers = {"Authorization": API_TOKEN}
|
30 |
response = requests.post(API_URL, headers=headers, json=payload)
|
31 |
+
|
32 |
+
# Initialize the response text with an error message by default
|
33 |
+
response_text = f"API call failed with status code {response.status_code}"
|
34 |
+
|
35 |
if response.status_code == 200:
|
36 |
+
response_text = response.text # Get the raw text response
|
|
|
|
|
37 |
|
38 |
# Process the API response and update history
|
39 |
+
self.history.append(response_text)
|
40 |
+
|
41 |
+
# Log API request and response
|
42 |
+
logging.debug(f"API Request: {API_URL}, Payload: {payload}, Headers: {headers}")
|
43 |
+
logging.debug(f"API Response: {response.status_code}, Content: {response_text}")
|
44 |
+
|
45 |
+
# Return the response text
|
46 |
return response_text
|
47 |
|
48 |
bot = ChatBot()
|
|
|
61 |
|
62 |
iface.launch()
|
63 |
|
64 |
+
# Placeholder classes, replace with actual implementations
|
65 |
class KnowledgeBaseExample(KnowledgeBase):
|
66 |
def perform_semantic_search(self, query_text: str, desired_number_of_results: int) -> List[SemanticSearchResult]:
|
67 |
result_example = SemanticSearchResult(
|
|
|
91 |
],
|
92 |
port=5000
|
93 |
)
|
94 |
+
server.run()
|