Spaces:
Build error
Build error
File size: 3,098 Bytes
2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 1444bfd 2cabec5 34595a6 2cabec5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# import altair as alt
# import numpy as np
# import pandas as pd
# import streamlit as st
# """
# # Welcome to Streamlit!
# Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
# If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
# forums](https://discuss.streamlit.io).
# In the meantime, below is an example of what you can do with just a few lines of code:
# """
# num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
# num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
# indices = np.linspace(0, 1, num_points)
# theta = 2 * np.pi * num_turns * indices
# radius = indices
# x = radius * np.cos(theta)
# y = radius * np.sin(theta)
# df = pd.DataFrame({
# "x": x,
# "y": y,
# "idx": indices,
# "rand": np.random.randn(num_points),
# })
# st.altair_chart(alt.Chart(df, height=700, width=700)
# .mark_point(filled=True)
# .encode(
# x=alt.X("x", axis=None),
# y=alt.Y("y", axis=None),
# color=alt.Color("idx", legend=None, scale=alt.Scale()),
# size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
# ))
import streamlit as st
import os
from groq import Groq
# Custom function to load variables from a .env file
def load_dotenv(filepath=".env"):
try:
with open(filepath, "r") as f:
for line in f:
line = line.strip()
# Skip comments and empty lines
if not line or line.startswith("#"):
continue
if "=" in line:
key, value = line.split("=", 1)
os.environ.setdefault(key.strip(), value.strip())
except FileNotFoundError:
st.error("No .env file found. Please create one with your API key.")
except Exception as e:
st.error(f"Error loading .env file: {e}")
# Load environment variables from the .env file
load_dotenv()
def main():
st.title("Samyotech Chatbot")
# Fetch API key from environment variables
groq_api_key = os.environ.get("GROQ_API_KEY")
if groq_api_key:
client = Groq(api_key=groq_api_key)
st.write("### Chat with LLM")
user_input = st.text_area("Enter your message:")
if st.button("Generate Response"):
if user_input.strip():
try:
response = client.chat.completions.create(
model="llama-3.3-70b-versatile",
messages=[
{"role": "user", "content": user_input}
]
)
st.write("### Response:")
st.write(response.choices[0].message.content)
except Exception as e:
st.error(f"Error: {e}")
else:
st.warning("Please enter a message to generate a response.")
else:
st.error("API key not found. Please ensure your .env file contains GROQ_API_KEY.")
if __name__ == "__main__":
main()
|