From b441d79abf6120141fc3b5e9bf79c979abaf14c8 Mon Sep 17 00:00:00 2001 From: UJJWAL KUMAR <111566155+ujjwalkr7449@users.noreply.github.com> Date: Mon, 1 Sep 2025 22:11:38 +0530 Subject: [PATCH] Update streamlit_app.py --- streamlit_app.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 3a8699f..5a84836 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -1,5 +1,70 @@ +import google.generativeai as genai import streamlit as st +from google.generativeai.types import HarmCategory, HarmBlockThreshold -st.title('🎈 App Name') +# API configuration +genai.configure(api_key="AIzaSyAAHxBqPkHCxw1Y4zIGXkMSUKt11EsjI8c") -st.write('Hello world!') +# Generation configuration +generation_config = { + "temperature": 0, + "top_p": 0.95, + "top_k": 64, + "max_output_tokens": 200, + "response_mime_type": "text/plain", +} + +# Create the model +model = genai.GenerativeModel( + model_name="gemini-1.5-flash", + generation_config=generation_config, # type: ignore +) + +# Initialize the conversation history +history = [] + +# Function to interact with the model and return a response +def gemini_1(query): + chat_session = model.start_chat( + history=history + ) + response = chat_session.send_message(query) + model_response = response.text + # Update conversation history + history.append({"role": "user", "parts": [query]}) + history.append({"role": "model", "parts": [model_response]}) + return model_response + +# Streamlit UI setup +st.title("Welcome to Aushadi_veda_Chat_Bot") + +# Sidebar for additional information or settings +with st.sidebar: + st.header("Aushadi_veda", divider="rainbow") + st.write("Welcome to the Aushadi_veda_Chat_Bot AI chat interface!") + st.write("Ask me anything, and I'll provide responses based on your queries.") + +# Initialize session state for storing conversation messages +if "messages" not in st.session_state: + st.session_state.messages = [] + +# Display previous conversation messages +for message in st.session_state.messages: + with st.chat_message(message["role"]): + st.markdown(message["content"]) + +# Input area for the user to send messages +prompt = st.chat_input("How can I assist you today?") + +# If the user submits a query, process it and get a response +if prompt: + with st.chat_message("user"): + st.markdown(prompt) + st.session_state.messages.append({"role": "user", "content": prompt}) + + # Get the response from the model + response = gemini_1(prompt) + + with st.chat_message("assistant"): + st.markdown(response) + st.session_state.messages.append({"role":"assistant", "content":response})