Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from groq import Groq
|
4 |
+
|
5 |
+
# Set your Groq API key
|
6 |
+
os.environ["GROQ_API_KEY"] = "your_groq_api_key_here" # Replace with your actual API key
|
7 |
+
|
8 |
+
# Initialize the Groq client
|
9 |
+
client = Groq(
|
10 |
+
api_key=os.environ.get("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"),
|
11 |
+
)
|
12 |
+
|
13 |
+
def grammar_and_vocab_checker(input_text):
|
14 |
+
"""
|
15 |
+
Function to check grammar and suggest vocabulary improvements using Groq API.
|
16 |
+
"""
|
17 |
+
prompt = (
|
18 |
+
f"Correct any grammar errors and suggest better vocabulary for the following text:\n"
|
19 |
+
f"{input_text}\n"
|
20 |
+
f"Response:"
|
21 |
+
)
|
22 |
+
|
23 |
+
chat_completion = client.chat.completions.create(
|
24 |
+
messages=[
|
25 |
+
{
|
26 |
+
"role": "user",
|
27 |
+
"content": prompt,
|
28 |
+
}
|
29 |
+
],
|
30 |
+
model="llama3-8b-8192", # Specify the model
|
31 |
+
)
|
32 |
+
|
33 |
+
return chat_completion.choices[0].message.content
|
34 |
+
|
35 |
+
# Streamlit app UI
|
36 |
+
def main():
|
37 |
+
st.title("English Grammar and Vocabulary Checker")
|
38 |
+
st.write("Enter your text below to get grammar corrections and vocabulary suggestions.")
|
39 |
+
|
40 |
+
# Input text area
|
41 |
+
user_input = st.text_area("Your Text", placeholder="Type your text here...")
|
42 |
+
|
43 |
+
if st.button("Check"):
|
44 |
+
if user_input.strip():
|
45 |
+
with st.spinner("Processing..."):
|
46 |
+
try:
|
47 |
+
response = grammar_and_vocab_checker(user_input)
|
48 |
+
st.success("Here is the suggestion:")
|
49 |
+
st.write(response)
|
50 |
+
except Exception as e:
|
51 |
+
st.error(f"An error occurred: {e}")
|
52 |
+
else:
|
53 |
+
st.warning("Please enter some text to check.")
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
main()
|