Загрузка...

AI Chatbot with Gemma 2B & Streamlit in Python 🔥 | Build Your Own LLM App!

Want to build your own private AI chatbot using open-source tools? In this video, you’ll learn how to create a simple conversational chatbot using Gemma 2B LLM with Streamlit in Python.

🧠 Gemma 2B is a lightweight, open LLM by Google, perfect for local/offline AI apps.
💻 We use Streamlit to build an intuitive web interface for real-time chat.

🚀 What You’ll Learn:
How to set up Gemma 2B locally

Building a clean chat UI using Streamlit

Sending prompts and receiving responses from the LLM

Running everything offline without API calls

🛠️ Tech Stack:
Python

Gemma 2B LLM (via Ollama or other loaders)

Streamlit (for frontend UI)

LangChain (optional prompt management)

🎯 Perfect for:

AI/ML enthusiasts

Developers exploring local LLMs

Anyone looking to create their own private chatbot

👍 Like | 💬 Comment | 🔔 Subscribe
#GemmaLLM #AIChatbot #StreamlitApp #PythonAI #OfflineLLM #Gemma2B #LocalAI #opensourceai

Source code:
import streamlit as st
import requests

OLLAMA_URL = "http://localhost:11434/api/chat"
MODEL = "gemma:2b" # Use the memory-friendly Gemma 2B model

st.set_page_config(page_title="Gemma Chatbot", page_icon="🤖")
st.title("🤖 AI Chatbot using Gemma 2B (Offline with Ollama)")

# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []

# Input box
user_input = st.chat_input("Say something...")

if user_input:
# Display user message
st.chat_message("user").markdown(user_input)
st.session_state.messages.append({"role": "user", "content": user_input})

# Prepare Ollama API payload
payload = {
"model": MODEL,
"messages": st.session_state.messages,
"stream": False
}

try:
response = requests.post(OLLAMA_URL, json=payload)
response.raise_for_status()
reply = response.json()["message"]["content"]

# Display assistant reply
st.chat_message("assistant").markdown(reply)
st.session_state.messages.append({"role": "assistant", "content": reply})

except Exception as e:
st.error(f"Failed to get response from Ollama: {e}")

Видео AI Chatbot with Gemma 2B & Streamlit in Python 🔥 | Build Your Own LLM App! канала Shaileshkumar Singh
Яндекс.Метрика

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять