nananie143 commited on
Commit
3921722
·
verified ·
1 Parent(s): 898d453

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. Dockerfile +20 -0
  2. app.py +57 -35
Dockerfile CHANGED
@@ -1,12 +1,32 @@
1
  FROM python:3.10-slim
2
 
 
 
 
 
 
 
3
  WORKDIR /code
4
 
 
 
 
 
 
 
 
 
 
5
  COPY requirements.txt .
6
  RUN pip install --no-cache-dir -r requirements.txt
7
 
 
8
  COPY . .
9
 
 
 
 
 
10
  EXPOSE 7860
11
 
12
  CMD ["python", "app.py"]
 
1
  FROM python:3.10-slim
2
 
3
+ # Install system dependencies including DNS tools
4
+ RUN apt-get update && apt-get install -y \
5
+ curl \
6
+ dnsutils \
7
+ && rm -rf /var/lib/apt/lists/*
8
+
9
  WORKDIR /code
10
 
11
+ # Set DNS configuration
12
+ RUN echo "nameserver 8.8.8.8" > /etc/resolv.conf && \
13
+ echo "nameserver 8.8.4.4" >> /etc/resolv.conf
14
+
15
+ # Set network timeouts
16
+ ENV CURL_TIMEOUT=30
17
+ ENV REQUESTS_TIMEOUT=30
18
+
19
+ # Copy and install requirements
20
  COPY requirements.txt .
21
  RUN pip install --no-cache-dir -r requirements.txt
22
 
23
+ # Copy application code
24
  COPY . .
25
 
26
+ # Add healthcheck
27
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
28
+ CMD curl -f http://localhost:7860/ || exit 1
29
+
30
  EXPOSE 7860
31
 
32
  CMD ["python", "app.py"]
app.py CHANGED
@@ -11,6 +11,10 @@ from typing import Dict, Any, List
11
  import json
12
  from datetime import datetime
13
  import logging
 
 
 
 
14
 
15
  from agentic_system import AgenticSystem
16
  from team_management import TeamManager
@@ -21,11 +25,41 @@ from reasoning.unified_engine import UnifiedReasoningEngine
21
  logging.basicConfig(level=logging.INFO)
22
  logger = logging.getLogger(__name__)
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  class AgentInterface:
25
  """Interface for the agentic system."""
26
 
27
  def __init__(self):
28
  """Initialize the interface components."""
 
 
 
 
29
  self.orchestrator = AgentOrchestrator()
30
  self.reasoning_engine = UnifiedReasoningEngine(
31
  min_confidence=0.7,
@@ -49,61 +83,49 @@ class AgentInterface:
49
  context=context
50
  )
51
 
52
- if result.success:
53
- return result.answer
54
- else:
55
- return f"Error: Unable to process query. Please try again."
56
-
57
  except Exception as e:
58
  logger.error(f"Error processing query: {e}")
59
- return f"Error: {str(e)}"
60
 
61
  # Initialize interface
62
  interface = AgentInterface()
63
 
64
  # Create Gradio interface
65
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
66
- gr.Markdown("""
67
- # AI Reasoning System
68
- This system uses advanced reasoning strategies including local LLM for improved performance.
69
-
70
- Note: First query might take a few seconds as the model loads.
71
- """)
72
 
73
  with gr.Row():
74
- with gr.Column(scale=4):
75
  input_text = gr.Textbox(
76
- label="Your question",
77
- placeholder="Ask me anything...",
78
- lines=2
79
  )
 
 
 
80
  output_text = gr.Textbox(
81
  label="Response",
82
- lines=10,
83
- interactive=False
84
  )
85
- submit_btn = gr.Button("Ask")
86
- clear_btn = gr.Button("Clear")
87
-
88
- with gr.Column(scale=1):
89
- gr.Markdown("""
90
- ### Example Questions:
91
- - What are the implications of artificial intelligence on society?
92
- - How does climate change affect global ecosystems?
93
- - What are the philosophical implications of quantum mechanics?
94
- """)
95
 
96
- # Set up event handlers
97
  submit_btn.click(
98
  fn=interface.process_query,
99
  inputs=input_text,
100
  outputs=output_text
101
  )
102
- clear_btn.click(
103
- lambda: ("", ""),
104
- inputs=None,
105
- outputs=[input_text, output_text]
106
- )
 
 
 
 
 
107
 
108
  # Launch the interface
109
  if __name__ == "__main__":
 
11
  import json
12
  from datetime import datetime
13
  import logging
14
+ import os
15
+ import socket
16
+ import requests
17
+ from requests.adapters import HTTPAdapter, Retry
18
 
19
  from agentic_system import AgenticSystem
20
  from team_management import TeamManager
 
25
  logging.basicConfig(level=logging.INFO)
26
  logger = logging.getLogger(__name__)
27
 
28
+ # Configure network settings
29
+ TIMEOUT = int(os.getenv('REQUESTS_TIMEOUT', '30'))
30
+ RETRIES = 3
31
+
32
+ # Configure session with retries
33
+ session = requests.Session()
34
+ retries = Retry(total=RETRIES,
35
+ backoff_factor=1,
36
+ status_forcelist=[429, 500, 502, 503, 504])
37
+ session.mount('https://', HTTPAdapter(max_retries=retries))
38
+ session.mount('http://', HTTPAdapter(max_retries=retries))
39
+
40
+ def check_network():
41
+ """Check network connectivity."""
42
+ try:
43
+ # Try to resolve huggingface.co
44
+ socket.gethostbyname('huggingface.co')
45
+ # Try to connect to the API
46
+ response = session.get('https://huggingface.co/api/health',
47
+ timeout=TIMEOUT)
48
+ response.raise_for_status()
49
+ return True
50
+ except Exception as e:
51
+ logger.error(f"Network check failed: {e}")
52
+ return False
53
+
54
  class AgentInterface:
55
  """Interface for the agentic system."""
56
 
57
  def __init__(self):
58
  """Initialize the interface components."""
59
+ # Check network connectivity
60
+ if not check_network():
61
+ logger.warning("Network connectivity issues detected")
62
+
63
  self.orchestrator = AgentOrchestrator()
64
  self.reasoning_engine = UnifiedReasoningEngine(
65
  min_confidence=0.7,
 
83
  context=context
84
  )
85
 
86
+ return result.get('answer', 'No response generated')
87
+
 
 
 
88
  except Exception as e:
89
  logger.error(f"Error processing query: {e}")
90
+ return f"An error occurred: {str(e)}"
91
 
92
  # Initialize interface
93
  interface = AgentInterface()
94
 
95
  # Create Gradio interface
96
+ with gr.Blocks(title="Advanced Reasoning System") as demo:
97
+ gr.Markdown("# Advanced Reasoning System")
 
 
 
 
 
98
 
99
  with gr.Row():
100
+ with gr.Column():
101
  input_text = gr.Textbox(
102
+ label="Your Query",
103
+ placeholder="Enter your query here...",
104
+ lines=3
105
  )
106
+ submit_btn = gr.Button("Submit")
107
+
108
+ with gr.Column():
109
  output_text = gr.Textbox(
110
  label="Response",
111
+ lines=5
 
112
  )
 
 
 
 
 
 
 
 
 
 
113
 
 
114
  submit_btn.click(
115
  fn=interface.process_query,
116
  inputs=input_text,
117
  outputs=output_text
118
  )
119
+
120
+ # Start the server with health check endpoint
121
+ app = gr.mount_gradio_app(None, demo, path="/")
122
+
123
+ @app.get("/health")
124
+ async def health_check():
125
+ """Health check endpoint."""
126
+ if check_network():
127
+ return {"status": "healthy"}
128
+ return {"status": "degraded", "reason": "network_issues"}
129
 
130
  # Launch the interface
131
  if __name__ == "__main__":