Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from groq import Groq
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# Load environment variables from .env file
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
# Retrieve API key
|
| 10 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 11 |
+
|
| 12 |
+
# Validate API key
|
| 13 |
+
if not GROQ_API_KEY:
|
| 14 |
+
st.error("API key is missing! Please check your .env file or environment variables.")
|
| 15 |
+
st.stop()
|
| 16 |
+
|
| 17 |
+
# Initialize Groq client with API key
|
| 18 |
+
client = Groq(api_key=GROQ_API_KEY)
|
| 19 |
+
|
| 20 |
+
st.title("Health Assistant Chatbot")
|
| 21 |
+
|
| 22 |
+
user_input = st.text_input("Ask a health-related question:")
|
| 23 |
+
if st.button("Submit") and user_input:
|
| 24 |
+
response = client.chat.completions.create(
|
| 25 |
+
model="llama-3.3-70b-versatile",
|
| 26 |
+
messages=[{"role": "user", "content": user_input}],
|
| 27 |
+
temperature=0.6,
|
| 28 |
+
max_completion_tokens=4096,
|
| 29 |
+
top_p=0.95,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
st.write("### Response:")
|
| 33 |
+
st.write(response.choices[0].message.content)
|