Py.Cafe

Deusowyy/

smileperfect-texas-ai-assistant

🦷 SmilePerfect Texas - AI Assistant

DocsPricing
  • app.py
  • requirements.txt
app.py
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
import streamlit as st
from groq import Groq
import os

# Zabezpieczenie przed błędem w chmurze
# PyCafe (i inne chmury) przechowują klucz w zmiennych środowiskowych, a nie w pliku .env
api_key = os.environ.get("GROQ_API_KEY") 

# Inicjalizacja klienta Groq ze wstrzykniętym kluczem
client = Groq(api_key=api_key)

st.set_page_config(page_title="Dental AI Demo", page_icon="🦷")
st.title("🦷 SmilePerfect Texas - AI Assistant")
st.caption("Wersja demonstracyjna (Zasilana darmowym API Groq i modelem Llama 3.3).")

if "messages" not in st.session_state:
    system_prompt = """
    You are a friendly and professional virtual receptionist for 'SmilePerfect Dental Clinic' located in Austin, Texas.
    Your job is to answer basic patient questions and encourage them to book an appointment.
    
    Key Information:
    - Open: Monday to Friday, 8 AM to 5 PM.
    - Services: General dentistry, teeth whitening ($150), implants, emergency extraction.
    - Location: 123 Longhorn Blvd, Austin, TX.
    - Booking: Always tell users they can book by calling 555-0199 or leaving their email here.
    
    Rules:
    - Keep responses short, concise, and helpful.
    - Do NOT provide medical diagnoses.
    - ALWAYS reply in English.
    """
    
    st.session_state.messages = [
        {"role": "system", "content": system_prompt}
    ]
    
    st.session_state.messages.append(
        {"role": "assistant", "content": "Howdy! Welcome to SmilePerfect Dental. How can I help you smile brighter today? 😁"}
    )

for message in st.session_state.messages:
    if message["role"] != "system":
        with st.chat_message(message["role"]):
            st.markdown(message["content"])

user_input = st.chat_input("Type your message here...")

if user_input:
    with st.chat_message("user"):
        st.markdown(user_input)
    
    st.session_state.messages.append({"role": "user", "content": user_input})
    
    with st.chat_message("assistant"):
        message_placeholder = st.empty()
        full_response = ""
        
        try:
            # Używamy potężnego, darmowego modelu Llama 3.3 70B przez Groq
            stream = client.chat.completions.create(
                model="llama-3.3-70b-versatile",
                messages=st.session_state.messages,
                stream=True,
            )
            
            for chunk in stream:
                # Groq zwraca dane minimalnie inaczej, zabezpieczamy się przed pustymi tokenami
                if chunk.choices[0].delta.content is not None:
                    full_response += chunk.choices[0].delta.content
                    message_placeholder.markdown(full_response + "▌")
            
            message_placeholder.markdown(full_response)
            st.session_state.messages.append({"role": "assistant", "content": full_response})
            
        except Exception as e:
            st.error(f"API Error: {e}. Sprawdź swój klucz GROQ_API_KEY w pliku .env!")