Spaces:
Sleeping
Sleeping
Amelia-James
commited on
Commit
•
0dc7769
1
Parent(s):
f223900
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from groq import Groq
|
4 |
+
|
5 |
+
# Set your Groq API key here or load it from an environment variable
|
6 |
+
api_key = os.getenv("GROQ_API_KEY") # Or hardcode it securely
|
7 |
+
|
8 |
+
# Streamlit app setup
|
9 |
+
st.title("Groq API Content Writer Specialist")
|
10 |
+
st.write("Generate humanized, engaging content based on your input.")
|
11 |
+
|
12 |
+
if api_key:
|
13 |
+
# Initialize the Groq client with the pre-configured API key
|
14 |
+
client = Groq(api_key=api_key)
|
15 |
+
|
16 |
+
# User input for content requirements
|
17 |
+
user_input = st.text_input("Enter your topic or content requirements:")
|
18 |
+
|
19 |
+
if st.button("Generate Content"):
|
20 |
+
# Ensure user input is not empty
|
21 |
+
if user_input:
|
22 |
+
try:
|
23 |
+
# Set the role of the model as a "Humanized Content Writer"
|
24 |
+
system_message = {
|
25 |
+
"role": "system",
|
26 |
+
"content": "You are a skilled content writer specializing in creating humanized, engaging, and relatable content. Write with a conversational tone that connects with the reader, while still being professional and informative."
|
27 |
+
}
|
28 |
+
|
29 |
+
user_message = {
|
30 |
+
"role": "user",
|
31 |
+
"content": user_input
|
32 |
+
}
|
33 |
+
|
34 |
+
# Create the chat completion with a system role of a humanized content writer
|
35 |
+
chat_completion = client.chat.completions.create(
|
36 |
+
messages=[
|
37 |
+
system_message,
|
38 |
+
user_message
|
39 |
+
],
|
40 |
+
model="llama3-8b-8192", # Use your specific model here
|
41 |
+
)
|
42 |
+
|
43 |
+
# Display the response
|
44 |
+
response = chat_completion.choices[0].message.content
|
45 |
+
st.write("### Generated Humanized Content")
|
46 |
+
st.write(response)
|
47 |
+
except Exception as e:
|
48 |
+
st.error(f"An error occurred: {e}")
|
49 |
+
else:
|
50 |
+
st.warning("Please enter your content requirements before clicking 'Generate Content'")
|
51 |
+
else:
|
52 |
+
st.error("API key not found. Please set the API key in your environment.")
|