Afeezee commited on
Commit
46fbe73
·
verified ·
1 Parent(s): 4bb18ec

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from groq import Groq
3
+
4
+
5
+ # Configure Llama 3.1 and Gemma-2-9b (using the API key)
6
+ llama_client = Groq(api_key="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")
7
+
8
+ def paraphrase_with_llama(text):
9
+ completion = llama_client.chat.completions.create(
10
+ model="llama-3.1-70b-versatile",
11
+ messages=[
12
+ {
13
+ "role": "system",
14
+ "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."
15
+ },
16
+ {
17
+ "role": "user",
18
+ "content": text
19
+ }
20
+ ],
21
+ temperature=0.8,
22
+ max_tokens=2048,
23
+ top_p=1,
24
+ stream=True,
25
+ stop=None,
26
+ )
27
+ output = ""
28
+ for chunk in completion:
29
+ output += chunk.choices[0].delta.content or ""
30
+ return output
31
+
32
+ def paraphrase_with_gemma(text):
33
+ completion = llama_client.chat.completions.create(
34
+ model="gemma2-9b-it",
35
+ messages=[
36
+ {
37
+ "role": "system",
38
+ "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."
39
+ },
40
+ {
41
+ "role": "user",
42
+ "content": text
43
+ }
44
+ ],
45
+ temperature=0.8,
46
+ max_tokens=1024,
47
+ top_p=1,
48
+ stream=True,
49
+ stop=None,
50
+ )
51
+ output = ""
52
+ for chunk in completion:
53
+ output += chunk.choices[0].delta.content or ""
54
+ return output
55
+
56
+ def paraphrase(text, model_choice):
57
+ if model_choice == "Llama 3.1":
58
+ return paraphrase_with_llama(text)
59
+ elif model_choice == "Gemma-2-9b":
60
+ return paraphrase_with_gemma(text)
61
+ else:
62
+ return "Invalid model choice"
63
+
64
+ # Gradio Interface
65
+ def gradio_interface():
66
+ with gr.Blocks() as demo:
67
+ gr.Markdown("# Yipada")
68
+ gr.Markdown("**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.")
69
+
70
+ text_input = gr.Textbox(label="Input Text", placeholder="Enter the text you want to paraphrase here...")
71
+ model_choice = gr.Dropdown(choices=["Llama 3.1", "Gemma-2-9b"], label="Select Model", value="Llama 3.1")
72
+ output = gr.Textbox(label="Paraphrased Text")
73
+
74
+ paraphrase_button = gr.Button("Paraphrase")
75
+ paraphrase_button.click(paraphrase, inputs=[text_input, model_choice], outputs=output)
76
+
77
+ demo.launch()
78
+
79
+ if __name__ == "__main__":
80
+ gradio_interface()