🔧 Programmierung 🕛 vor 2 Jahren 4 Min Lesezeit
0

Building a Diet Assistant using Lyzr SDK

↗ Quelle (dev.to)
🗣️ Stimme:

In today’s fast-paced world, maintaining a balanced diet can be challenging. However, with the Diet Assistant powered by Lyzr SDK, you can now effortlessly track and optimize your nutrition. This blog post will walk you through the incredible features of the Diet Assistant and how it can transform your dietary habits for the better.





Lets get Started!



Create an app.py file




CODE
import streamlit as st
from lyzr_automata.ai_models.openai import OpenAIModel
from lyzr_automata import Agent, Task
from lyzr_automata.pipelines.linear_sync_pipeline import LinearSyncPipeline
from PIL import Image
from lyzr_automata.tasks.task_literals import InputType, OutputType
import os






This code creates a Streamlit app using the Lyzr Automata SDK and OpenAI’s language model to build a diet assistant tool. It imports necessary libraries for the web interface, AI model, and image handling. The OpenAI API key is set from Streamlit secrets. The app hides the default header, displays a logo, and provides a text input for users to log their food intake. An OpenAIModel instance is configured with specific parameters. The generation function defines an AI agent to analyze the user's input and provide nutritional insights.




CODE
# Set the OpenAI API key
os.environ["OPENAI_API_KEY"] = st.secrets["apikey"]






This line sets the OpenAI API key as an environment variable, retrieving it securely from Streamlit’s secrets for authentication.




CODE
input = st.text_input("Please enter your daily food intake:",placeholder=f"""Type here""")






This line creates a text input field in a Streamlit app where users can enter their daily food intake. It includes a label and a placeholder text to guide the user.




CODE
open_ai_text_completion_model = OpenAIModel(
api_key=st.secrets["apikey"],
parameters={
"model": "gpt-4-turbo-preview",
"temperature": 0.2,
"max_tokens": 1500,
},
)






This code instantiates an OpenAIModel object from the lyzr_automata package, configuring it to use the GPT-4 language model with specific parameters. It securely retrieves the API key from Streamlit's secrets for authentication.




CODE
def generation(input):
generator_agent = Agent(
role=" Expert DIETITIAN ",
prompt_persona=f"Your task is to EMPOWER users to TRACK and ANALYZE their DAILY FOOD INTAKE.")
prompt = f"""
[Prompts here]
"""






This function generation defines an AI agent using the Agent class from the Lyzr Automata package. The agent is assigned the role of an "Expert Dietitian" with a specified prompt persona. The prompt persona instructs the agent on its task, which is to empower users to track and analyze their daily food intake.




CODE
   generator_agent_task = Task(
name="Generation",
model=open_ai_text_completion_model,
agent=generator_agent,
instructions=prompt,
default_input=input,
output_type=OutputType.TEXT,
input_type=InputType.TEXT,
).execute()

return generator_agent_task






This code snippet creates a task instance named “Generation” using the Lyzr Automata package’s Task class. It specifies parameters such as the model (open_ai_text_completion_model), agent (generator_agent), instructions (the prompt defined earlier), default input (user input), and output/input types. The execute() method is called to execute the task, and the result is returned.




CODE
if st.button("Insights"):
solution = generation(input)
st.markdown(solution)






This piece of code creates a button using Streamlit’s st.button() function. When the button labeled "Insights" is clicked, it triggers the generation() function, passing the user input (input) as an argument. The result of the function execution is stored in the solution variable, which is then displayed using Streamlit's st.markdown() function.



App link:



The Diet Assistant is powered by the Lyzr Automata Agent, utilizing the capabilities of OpenAI’s GPT-4 Turbo. For any inquiries or issues, please contact Lyzr. You can learn more about Lyzr and their offerings through the following links:



Website:

Discord:

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Razer's new Tartarus V2 Pro is the weirdest gaming keyboard I've ever wanted, loaded with fancy switches and ergonomic relief
1 Quelle
HMX 6 mit Cortana-KI auf der zweiten RTX 5090 – Rückblick auf die HMX Pro
1 Quelle
Huawei ist gelungen, wovon Smartphone-Besitzer seit Jahren träumen
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Building a Diet Assistant using Lyzr SDK

Thematisch verwandte Begriffe: Building, Diet, Assistant, using · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...