File size: 3,368 Bytes
46fbe73
 
e3846a9
46fbe73
e3846a9
46fbe73
 
e3846a9
46fbe73
 
 
 
 
 
 
e7a8d79
46fbe73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c6c196
46fbe73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
884c29a
d184a40
46fbe73
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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()