matterattetatte commited on
Commit
2bcb787
·
verified ·
1 Parent(s): c9f0eeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -14
app.py CHANGED
@@ -1,10 +1,102 @@
1
  import streamlit as st
2
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
3
 
4
- # Define the blog-writing agent with DuckDuckGo tool
5
- blog_agent = CodeAgent(
6
- tools=[DuckDuckGoSearchTool()],
7
- model=HfApiModel()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  )
9
 
10
  # Function to log agent actions
@@ -16,27 +108,27 @@ def log_agent_action(prompt, result, agent_name):
16
  st.code(result, language="text")
17
 
18
  # Streamlit app title
19
- st.title("AI Blog Writing Agent with Real-Time Insights")
20
 
21
  # App description
22
- st.write("Generate creative blogs enriched with real-time insights using the AI Blog Writing Agent powered by SmolAgents and DuckDuckGo.")
23
 
24
  # Input blog topic or prompt
25
- blog_prompt = st.text_area("Enter your blog topic or prompt:", placeholder="E.g., The Future of AI in Healthcare")
26
 
27
  # Button to generate blog content
28
- if st.button("Generate Blog Content"):
29
- if blog_prompt:
30
- with st.spinner("Generating blog content with real-time insights..."):
31
  try:
32
  # Run the blog agent with the given prompt
33
- blog_result = blog_agent.run(blog_prompt)
34
  # Display the generated blog content
35
- st.subheader("Generated Blog Content:")
36
- st.write(blog_result)
37
 
38
  # Log backend activity
39
- log_agent_action(blog_prompt, blog_result, "Blog Writing Agent with DuckDuckGo")
40
  except Exception as e:
41
  st.error(f"An error occurred: {e}")
42
  else:
 
1
  import streamlit as st
2
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
3
 
4
+
5
+ examples = """
6
+ Here are a few examples:
7
+
8
+ Task: Today, I had an appointment with Bella, a 5-year-old Golden Retriever owned by John Smith. She came in for her annual check-up. Bella weighs 25 kilograms and is in great condition overall.
9
+
10
+ During the exam, I checked her vital signs: her temperature was 38.5°C, her heart rate was 80 bpm, and her respiratory rate was 20 breaths per minute—all perfectly normal. Her coat was shiny and free of any abnormalities, her eyes were clear with no discharge, and her ears showed no signs of infection. I did notice some mild tartar on her teeth, which I mentioned to John, and her skin was healthy with no rashes or lesions.
11
+
12
+ As part of her routine care, I administered her rabies vaccine, which was due, and confirmed that her distemper vaccination is up to date. We also performed a fecal test and a heartworm test, both of which came back negative.
13
+
14
+ For prevention, I prescribed her a monthly heartworm medication and provided her with flea and tick prevention. I told John that Bella is healthy and has no current health concerns. I recommended he continue her balanced diet, keep up her regular exercise, and return in a year for her next check-up.
15
+
16
+ It was a pleasure to see Bella, and I look forward to her next visit. – Dr. Emily Carter
17
+
18
+
19
+ Final answer:
20
+
21
+ Date of Visit January 9, 2025
22
+ Pet's Name Bella
23
+ Species Dog
24
+ Breed Golden Retriever
25
+ Age 5 years
26
+ Weight 25 kg
27
+ Owner's Name John Smith
28
+ Reason for Visit Annual Check-up
29
+ Vital Signs - Temperature: 38.5°C
30
+ - Heart Rate: 80 bpm
31
+ - Respiratory Rate: 20/min
32
+ Physical Exam - Coat: Shiny, no abnormalities
33
+ - Eyes: Clear, no discharge
34
+ - Ears: No signs of infection
35
+ - Teeth: Mild tartar
36
+ - Skin: No rashes or lesions
37
+ Vaccinations - Rabies Vaccine: Administered
38
+ - Distemper: Up to date
39
+ Tests Performed - Fecal Test: Negative
40
+ - Heartworm Test: Negative
41
+ Medications - Monthly Heartworm Prevention prescribed
42
+ - Flea and Tick prevention given
43
+ Diagnosis Healthy; No concerns detected
44
+ Recommendations - Continue balanced diet
45
+ - Regular exercise
46
+ - Return in 1 year for next annual check-up
47
+ Veterinarian Dr. Emily Carter
48
+
49
+ """
50
+
51
+ """You're a helpful agent named '{name}'.
52
+ You have been submitted this task by your manager.
53
+ ---
54
+ Task:
55
+ {task}
56
+ ---
57
+ You're helping your manager solve a wider task: so make sure to not provide a one-line answer, but give as much information as possible to give them a clear understanding of the answer.
58
+
59
+ Your final_answer WILL HAVE to contain these parts:
60
+ ### 1. Task outcome (short version):
61
+ ### 2. Task outcome (extremely detailed version):
62
+ ### 3. Additional context (if relevant):
63
+
64
+ Put all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.
65
+ And even if your task resolution is not successful, please return as much context as possible, so that your manager can act upon this feedback.
66
+ {{additional_prompting}}"""
67
+
68
+ sys_admin_prompt = f"""
69
+ You are a systems admin at a veterinary clinic. It is your job to organize my reports.
70
+
71
+ Here is my report:
72
+
73
+ {{task}}
74
+
75
+ Here are a few examples of previous tasks
76
+
77
+ {{additional_prompting}}
78
+ """
79
+
80
+
81
+ admin_agent = CodeAgent(
82
+ tools=[],
83
+ model=HfApiModel(),
84
+ max_steps=6,
85
+ )
86
+
87
+ managed_admin_agent = ManagedAgent(
88
+ agent=admin_agent,
89
+ name="system admin",
90
+ managed_agent_prompt=sys_admin_prompt,
91
+ additional_prompting=examples,
92
+ description="Returns a rough draft of an organized report",
93
+ )
94
+
95
+ manager_agent = CodeAgent(
96
+ tools=[],
97
+ model=HfApiModel(),
98
+ managed_agents=[managed_admin_agent],
99
+ max_steps=6,
100
  )
101
 
102
  # Function to log agent actions
 
108
  st.code(result, language="text")
109
 
110
  # Streamlit app title
111
+ st.title("AI Veterinary Assistant Agent organizing reports")
112
 
113
  # App description
114
+ st.write("Generate reports enriched with real-time insights using the AI Veterinary Report Writing Agent powered by SmolAgents and DuckDuckGo.")
115
 
116
  # Input blog topic or prompt
117
+ prompt = st.text_area("Enter the description of your patient visit:", placeholder="E.g., Today, I helped Max, a 5 year old Chihuahua")
118
 
119
  # Button to generate blog content
120
+ if st.button("Generate Report"):
121
+ if prompt:
122
+ with st.spinner("Generating blog content..."):
123
  try:
124
  # Run the blog agent with the given prompt
125
+ result = manager_agent.run(prompt)
126
  # Display the generated blog content
127
+ st.subheader("Generated Report:")
128
+ st.write(result)
129
 
130
  # Log backend activity
131
+ log_agent_action(prompt, result, "Blog Writing Agent with DuckDuckGo")
132
  except Exception as e:
133
  st.error(f"An error occurred: {e}")
134
  else: