|
import streamlit as st |
|
from phi.agent import Agent |
|
from phi.model.google import Gemini |
|
import tempfile |
|
import os |
|
|
|
def main(): |
|
|
|
agent = Agent( |
|
model=Gemini(id="gemini-2.0-flash-thinking-exp-1219"), |
|
markdown=True |
|
) |
|
|
|
|
|
st.title("Multimodal Reasoning AI Agent 🧠") |
|
|
|
|
|
st.write( |
|
"Upload an image and provide a reasoning-based task for the AI Agent. " |
|
"The AI Agent will analyze the image and respond based on your input." |
|
) |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"]) |
|
|
|
if uploaded_file is not None: |
|
try: |
|
|
|
with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as tmp_file: |
|
tmp_file.write(uploaded_file.getvalue()) |
|
temp_path = tmp_file.name |
|
|
|
|
|
st.image(uploaded_file, caption="Uploaded Image", use_container_width=True) |
|
|
|
|
|
task_input = st.text_area( |
|
"Enter your task/question for the AI Agent:" |
|
) |
|
|
|
|
|
if st.button("Analyze Image") and task_input: |
|
with st.spinner("AI is thinking... 🤖"): |
|
try: |
|
|
|
response = agent.run(task_input, images=[temp_path]) |
|
|
|
|
|
st.markdown("### AI Response:") |
|
st.markdown(response.content) |
|
except Exception as e: |
|
st.error(f"An error occurred during analysis: {str(e)}") |
|
finally: |
|
|
|
if os.path.exists(temp_path): |
|
os.unlink(temp_path) |
|
|
|
except Exception as e: |
|
st.error(f"An error occurred while processing the image: {str(e)}") |
|
|
|
if __name__ == "__main__": |
|
main() |