Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,6 @@ logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %
|
|
14 |
# =============================================================================
|
15 |
# Load In-House Hugging Face Models for AI Agents with Fallbacks
|
16 |
# =============================================================================
|
17 |
-
# Replace these model IDs with your actual in-house model names and token if available.
|
18 |
try:
|
19 |
summarizer = pipeline("summarization", model="myorg/inhouse-summarizer")
|
20 |
logging.info("Loaded in-house summarizer.")
|
@@ -36,6 +35,51 @@ except Exception as e:
|
|
36 |
logging.error("In-house planner generator not found, falling back: %s", e)
|
37 |
planner_generator = pipeline("text-generation", model="gpt2", max_length=150)
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
# =============================================================================
|
40 |
# Helper Functions: Interactive Chart Generators
|
41 |
# =============================================================================
|
|
|
14 |
# =============================================================================
|
15 |
# Load In-House Hugging Face Models for AI Agents with Fallbacks
|
16 |
# =============================================================================
|
|
|
17 |
try:
|
18 |
summarizer = pipeline("summarization", model="myorg/inhouse-summarizer")
|
19 |
logging.info("Loaded in-house summarizer.")
|
|
|
35 |
logging.error("In-house planner generator not found, falling back: %s", e)
|
36 |
planner_generator = pipeline("text-generation", model="gpt2", max_length=150)
|
37 |
|
38 |
+
# =============================================================================
|
39 |
+
# In-House Agent Functions
|
40 |
+
# =============================================================================
|
41 |
+
def report_agent(data):
|
42 |
+
"""
|
43 |
+
Generates a summary report using the in-house summarizer model.
|
44 |
+
"""
|
45 |
+
if not data or len(data.strip()) == 0:
|
46 |
+
return "Please provide input text for summarization."
|
47 |
+
try:
|
48 |
+
summary = summarizer(data, max_length=130, min_length=30, do_sample=False)
|
49 |
+
logging.debug("Summary generated using in-house summarizer.")
|
50 |
+
return summary[0]['summary_text']
|
51 |
+
except Exception as e:
|
52 |
+
logging.error("Error generating summary: %s", e)
|
53 |
+
return "Error generating summary."
|
54 |
+
|
55 |
+
def planning_agent(goal):
|
56 |
+
"""
|
57 |
+
Generates a detailed action plan based on the provided goal using the in-house planner model.
|
58 |
+
"""
|
59 |
+
if not goal or len(goal.strip()) == 0:
|
60 |
+
return "Please provide a goal for planning."
|
61 |
+
try:
|
62 |
+
plan = planner_generator(goal, max_length=150, num_return_sequences=1)
|
63 |
+
logging.debug("Plan generated using in-house planner.")
|
64 |
+
return plan[0]['generated_text']
|
65 |
+
except Exception as e:
|
66 |
+
logging.error("Error generating plan: %s", e)
|
67 |
+
return "Error generating plan."
|
68 |
+
|
69 |
+
def research_agent(query):
|
70 |
+
"""
|
71 |
+
Generates research insights based on the provided query using the in-house research generator.
|
72 |
+
"""
|
73 |
+
if not query or len(query.strip()) == 0:
|
74 |
+
return "Please provide a research query."
|
75 |
+
try:
|
76 |
+
result = research_generator(query, max_length=100, num_return_sequences=1)
|
77 |
+
logging.debug("Research output generated using in-house research model.")
|
78 |
+
return result[0]['generated_text']
|
79 |
+
except Exception as e:
|
80 |
+
logging.error("Error generating research output: %s", e)
|
81 |
+
return "Error generating research output."
|
82 |
+
|
83 |
# =============================================================================
|
84 |
# Helper Functions: Interactive Chart Generators
|
85 |
# =============================================================================
|