Created
September 16, 2024 05:52
-
-
Save karthik4579/d902f8db3f160fb794dbf75b5815b33b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import streamlit as st | |
| from groq import Groq | |
| # Initialize Groq client | |
| client = Groq(api_key="YOUR_GROQ_API_KEY") | |
| # Streamlit UI | |
| st.title("Grammar Correction App") | |
| st.write("Enter text below to get grammar corrections:") | |
| input_text = st.text_area("Input Text", height=200) | |
| if st.button("Correct Grammar"): | |
| if input_text: | |
| # Define the prompt | |
| prompt = f""" | |
| Your role is of an English professor. Analyze the given text that is delimited by the text 'INPUT TEXT'. From the given text, identify all the sentences that are grammatically incorrect and return it as a valid JSON. Make sure that it is a list of instructions on what needs to be changed to what. The key in the JSON should be the original sentence and the value should be the corrected sentence. Include all corrections in one JSON object and respond using a valid JSON. Also, include 2 extra key-value pairs in the beginning as "original": "generated" to be considered as column headers. Strictly follow this format and do not include any long explanations. Ensure grammatical correctness and look for niche grammatical mistakes while maintaining accuracy and original context. Include all possible grammatical mistakes that can improve the writing overall. | |
| INPUT TEXT: {input_text} | |
| """ | |
| # Define the parameters | |
| params = { | |
| "model": "mixtral-8x7b-32768", | |
| "temperature": 0.5, | |
| "top_p": 0.55, | |
| "stream": False, | |
| "max_tokens": 4000, | |
| "response_format": {"type": "json_object"} | |
| } | |
| # Get the response from Groq | |
| response = client.chat_completions.create( | |
| messages=[{"role": "user", "content": prompt}], | |
| **params | |
| ) | |
| # Display the corrections | |
| corrections = response.choices[0].message.content | |
| st.json(corrections) | |
| else: | |
| st.write("Please enter some text to correct.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment