Spaces:
Sleeping
Sleeping
import os | |
import gradio as gr | |
from groq import Groq | |
client = Groq(api_key='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') | |
# Define system message | |
system_prompt = '''IDENTITY and PURPOSE | |
You are an academic writing expert. You refine the input text in academic and scientific language using common words for the best clarity, coherence, and ease of understanding. | |
Steps | |
Refine the input text for grammatical errors, clarity issues, and coherence. | |
Refine the input text into academic voice. | |
Use formal English only. | |
Tend to use common and easy-to-understand words and phrases. | |
Avoid wordy sentences. | |
Avoid trivial statements. | |
Avoid using the same words and phrases repeatedly. | |
Apply corrections and improvements directly to the text. | |
Maintain the original meaning and intent of the user's text. | |
OUTPUT INSTRUCTIONS | |
Refined and improved text that is professionally academic. | |
A list of changes made to the original text.''' | |
# Initialize chat history list with system message | |
chat_history = [ | |
{ | |
"role": "system", | |
"content": system_prompt, | |
} | |
] | |
# Function to add a message to the chat history and get a response | |
def chat_with_model(message, chat_history): | |
# Add user message to chat history | |
chat_history.append({ | |
"role": "user", | |
"content": message, | |
}) | |
# Get response from model | |
chat_completion = client.chat.completions.create( | |
messages=chat_history, | |
model="llama3-70b-8192", | |
) | |
# Extract assistant's message | |
assistant_message = chat_completion.choices[0].message.content | |
# Add assistant message to chat history | |
chat_history.append({ | |
"role": "assistant", | |
"content": assistant_message, | |
}) | |
return assistant_message | |
# Function to handle Gradio interface | |
def gradio_chat(user_input): | |
global chat_history | |
response = chat_with_model(user_input, chat_history) | |
return response | |
# Create Gradio interface | |
iface = gr.Interface( | |
fn=gradio_chat, | |
inputs="text", | |
outputs="text", | |
title="Yuni", | |
description="Enter your message below and interact with the language model." | |
) | |
# Launch Gradio interface | |
iface.launch() |