Create Chat bot application using Python, Streamlit and Gemini AI

In this article I am going to explain creating chat bot application using Python, Streamlit library and Gemini AI. In this chat bot application application will be self host with specific port on computer ad can be accessible from browser.

 


 

following Prerequisites required for development of this application :

  1. Visual studio code
  2. Python
  3. Api Key of Gemini can be obtain from https://aistudio.google.com  

Open visual studio code and create the file with name "chatbot.py". Now in visual studio code and go to terminal menu and click on New terminal link it will open new terminal. In terminal enter below command to install the Google generative AI library and steamlit library in your machine.

 

 pip install google-generativeai langchain-google-genai streamlit  

 Now copy below code and paste in the "chatbot.py" file.

 import streamlit as st  
 import google.generativeai as genai  
 genai.configure(api_key="enter your key obtain from aistudio.google.com")  
 model=genai.GenerativeModel(model_name="gemini-pro")  
 st.title("Gemini chat app")  
 if "messages" not in st.session_state:  
   st.session_state.messages=[  
     {  
       "role":"assistant",  
       "content":"enter the question"  
     }  
   ]  
 for message in st.session_state.messages:  
   with st.chat_message( message["role"]) :   
       st.markdown(message["content"])  
 def llmCall(query):  
    response=model.generate_content(query)  
    with st.chat_message("assistant"):  
      st.markdown(response.text)  
    st.session_state.messages.append(  
     {  
       "role": "user",  
       "content": query  
     }  
   )  
    st.session_state.messages.append(  
     {  
       "role": "assistant",  
       "content": response.text  
     }  
   )  
 query=st.chat_input("what is your question?")  
 if query:  
    with st.chat_message("user"):  
      st.markdown(query)    
    llmCall(query=query)  

Now enter below command to run the application.

 python -m stremlit run chatbot.py  

this will self host the application on your machine on with default port 8501 and application can be accessible by URL http://localhost:8501 as per below screenshot.

 


This way you can easily create the chat bot application with minimal code using python and streamlit library.

 

Comments

  1. App has been pretty convenient for watching content, but I did run into a Login problem that I could not figure out at first. Your article gave me a much better idea of where to start. Instead of immediately reinstalling everything, I checked my connection and restarted the application. That actually helped me narrow down the issue. I also found the information about Freecine APK versions useful because I had been using the same version for quite a while. The article feels practical and easy to understand, especially for people who are not familiar with troubleshooting Link applications. I will definitely keep these steps in mind.

    ReplyDelete

Post a Comment

Popular posts from this blog

Restore the lost focus of Auto post back controls in asp.net update Panel control

Use Chroma DB vector database in RAG application using llama index & Deepseek R1 local model

I have created an application to extract text from image using AI

Add Comma automatically while entering amounts in textbox using Javascript

Download DeepSeek R1 Model Locally free | AI RAG with LlamaIndex, Local Embedding and Ollama