Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,39 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
-
from groq import Groq
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
api_key=os.environ.get("GROQ_API_KEY") # Use the environment variable for the API key
|
| 11 |
-
)
|
| 12 |
|
| 13 |
-
# Function to
|
| 14 |
def get_chat_completion(user_message):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
],
|
| 23 |
-
model
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
#
|
| 30 |
def writing_prompt():
|
| 31 |
st.title("English Writing Assistant - Writing Prompt")
|
| 32 |
st.write("Write a paragraph about your favorite book.")
|
|
@@ -41,7 +48,7 @@ def writing_prompt():
|
|
| 41 |
else:
|
| 42 |
st.write("Please write your paragraph first.")
|
| 43 |
|
| 44 |
-
#
|
| 45 |
def reading_comprehension():
|
| 46 |
st.title("Reading Comprehension Assistant")
|
| 47 |
|
|
@@ -68,7 +75,7 @@ def reading_comprehension():
|
|
| 68 |
def main():
|
| 69 |
st.title("English Learning Assistant with Groq API")
|
| 70 |
|
| 71 |
-
#
|
| 72 |
option = st.selectbox("Choose an activity", ["Writing Prompt", "Reading Comprehension"])
|
| 73 |
|
| 74 |
if option == "Writing Prompt":
|
|
|
|
| 1 |
import os
|
| 2 |
+
import requests
|
| 3 |
import streamlit as st
|
|
|
|
| 4 |
|
| 5 |
+
# Set the Groq API key from environment variables
|
| 6 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY", "your-api-key-here") # Replace with your actual API key if needed
|
| 7 |
|
| 8 |
+
# The API URL (update with the correct URL if needed)
|
| 9 |
+
GROQ_API_URL = 'https://api.groq.com/v1/chat/completions' # Update with actual endpoint
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Function to interact with the Groq API
|
| 12 |
def get_chat_completion(user_message):
|
| 13 |
+
headers = {
|
| 14 |
+
'Authorization': f'Bearer {GROQ_API_KEY}',
|
| 15 |
+
'Content-Type': 'application/json',
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
# Prepare the request payload
|
| 19 |
+
payload = {
|
| 20 |
+
"messages": [
|
| 21 |
+
{"role": "user", "content": user_message}
|
| 22 |
],
|
| 23 |
+
"model": "llama3-8b-8192", # Replace with the model you're using
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
# Send the request to the API
|
| 27 |
+
response = requests.post(GROQ_API_URL, json=payload, headers=headers)
|
| 28 |
|
| 29 |
+
if response.status_code == 200:
|
| 30 |
+
# Return the response content
|
| 31 |
+
return response.json()['choices'][0]['message']['content']
|
| 32 |
+
else:
|
| 33 |
+
# Handle error response
|
| 34 |
+
return f"Error: {response.status_code} - {response.text}"
|
| 35 |
|
| 36 |
+
# Streamlit Writing Prompt
|
| 37 |
def writing_prompt():
|
| 38 |
st.title("English Writing Assistant - Writing Prompt")
|
| 39 |
st.write("Write a paragraph about your favorite book.")
|
|
|
|
| 48 |
else:
|
| 49 |
st.write("Please write your paragraph first.")
|
| 50 |
|
| 51 |
+
# Streamlit Reading Comprehension
|
| 52 |
def reading_comprehension():
|
| 53 |
st.title("Reading Comprehension Assistant")
|
| 54 |
|
|
|
|
| 75 |
def main():
|
| 76 |
st.title("English Learning Assistant with Groq API")
|
| 77 |
|
| 78 |
+
# Choose between activities
|
| 79 |
option = st.selectbox("Choose an activity", ["Writing Prompt", "Reading Comprehension"])
|
| 80 |
|
| 81 |
if option == "Writing Prompt":
|