Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from groq import Groq | |
| import time | |
| import matplotlib.pyplot as plt | |
| # API Key (replace with yours) | |
| 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="shirt_template.png", layout="wide") | |
| # 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"**Model Response:** {response}") | |
| # Success message animation | |
| st.success("Response retrieved successfully!") | |
| # Example of a simple chart (if applicable) | |
| if "chart" in response.lower(): | |
| # Generate some random data | |
| x = [1, 2, 3, 4, 5] | |
| y = [2, 4, 5, 4, 5] | |
| # Create a simple line chart | |
| plt.plot(x, y) | |
| plt.xlabel("X-axis") | |
| plt.ylabel("Y-axis") | |
| plt.title("Simple Line Chart") | |
| st.pyplot(plt) | |
| # Additional tips: | |
| # - Use custom CSS to style the app further. | |
| # - Explore Streamlit's components library for more interactive elements. | |
| # - Consider using a library like `plotly` for more advanced visualizations. | |
| # - Implement error handling and logging for a robust app. | |
| # - Test your app thoroughly on different browsers and devices. |