Yipada / app.py
Afeezee's picture
Update app.py
e3846a9 verified
import gradio as gr
from groq import Groq
import os
api_key = os.getenv("Yipada")
# Configure Llama 3.1 and Gemma-2-9b (using the API key)
llama_client = Groq(api_key= api_key)
def paraphrase_with_llama(text):
completion = llama_client.chat.completions.create(
model="llama-3.1-70b-versatile",
messages=[
{
"role": "system",
"content": "You are a versed English paraphraser assistant who doubles as an English professor with over 30 years experience writing, paraphrasing, teaching and contributing to the field of English language. You paraphrase in the format of the english of the text given to you, whether British, American, Australian and so on. Don't write any text apart from the paraphrased text."
},
{
"role": "user",
"content": text
}
],
temperature=0.8,
max_tokens=2048,
top_p=1,
stream=True,
stop=None,
)
output = ""
for chunk in completion:
output += chunk.choices[0].delta.content or ""
return output
def paraphrase_with_gemma(text):
completion = llama_client.chat.completions.create(
model="gemma2-9b-it",
messages=[
{
"role": "system",
"content": "You are a versed English paraphraser assistant who doubles as an English professor with over 30 years experience writing, paraphrasing, teaching and contributing to the field of English language. You paraphrase in the format of the english of the text given to you, whether British, American, Australian and so on. Don't write any text apart from the paraphrased text."
},
{
"role": "user",
"content": text
}
],
temperature=0.8,
max_tokens=1024,
top_p=1,
stream=True,
stop=None,
)
output = ""
for chunk in completion:
output += chunk.choices[0].delta.content or ""
return output
def paraphrase(text, model_choice):
if model_choice == "Llama 3.1":
return paraphrase_with_llama(text)
elif model_choice == "Gemma-2-9b":
return paraphrase_with_gemma(text)
else:
return "Invalid model choice"
# Gradio Interface
def gradio_interface():
with gr.Blocks() as demo:
gr.Markdown("<h1 style='text-align: center;'>Yipada</h1>")
gr.Markdown("<p style='text-align: center;'>Yipada is a versatile paraphrasing tool designed to help you rephrase your text with precision and clarity. Leveraging advanced language models, Yipada offers two powerful options: Llama 3.1 and Gemma-2-9b. Whether you need a formal rephrasing or a more creative twist, Yipada ensures that your text retains its original meaning while offering a fresh perspective.")
text_input = gr.Textbox(label="Input Text", placeholder="Enter the text you want to paraphrase here...")
model_choice = gr.Dropdown(choices=["Llama 3.1", "Gemma-2-9b"], label="Select Model", value="Llama 3.1")
output = gr.Textbox(label="Paraphrased Text")
paraphrase_button = gr.Button("Paraphrase")
paraphrase_button.click(paraphrase, inputs=[text_input, model_choice], outputs=output)
demo.launch()
if __name__ == "__main__":
gradio_interface()