File size: 1,595 Bytes
d06a9da
 
abe8342
7b59887
d06a9da
abe8342
d06a9da
 
 
443d818
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d06a9da
 
eb56ac7
d06a9da
abe8342
 
 
 
 
 
 
 
 
 
443d818
abe8342
aa8ab73
 
abe8342
 
d06a9da
443d818
 
62a8e7c
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
import streamlit as st
from groq import Groq
import time
import matplotlib.pyplot as plt

API_KEY = "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"

# Function to interact with the model
def get_model_response(prompt):
  try:
    client = Groq(api_key=API_KEY)
    chat_completion = client.chat.completions.create(
        messages=[
            {
                "role": "user",
                "content": prompt,
            }
        ],
        model="llama3-8b-8192",  # Update with your desired model
    )
    response = chat_completion.choices[0].message.content
    return response
  except Exception as e:
    return f"An error occurred: {str(e)}"

# Streamlit App
st.set_page_config(page_title="AI Chat Interface", page_icon='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRDtq0iX3NP1eu6DiEnnmm1moWENvPHYNsMZQ&s', layout="wide")  # Removed semicolon

# Add a header with logo (optional)
st.markdown("""
<div style="text-align: center;">
  <img src="https://placehold.it/150x150" alt="Logo" style="border-radius: 50%;">
  <h1>AI Chat Interface</h1>
</div>
""", unsafe_allow_html=True)

# Progress bar animation for loading
with st.spinner("Thinking..."):
  time.sleep(2)  # Simulate processing time

# User input with placeholder and help text
user_input = st.text_input("Your Prompt", placeholder="Type your question here...", help="Feel free to ask anything!")

# Display "Thinking..." animation while fetching response
if st.button("Get Response"):
  with st.spinner("Fetching Response..."):
    response = get_model_response(user_input)
  st.write(f" {response}")