[quickadvancetools-awais-dev]
commited on
Commit
·
c488daa
1
Parent(s):
d5f12b9
Add application file
Browse files- README.md +4 -4
- app.py +77 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
---
|
| 2 |
title: WritingnParaphrasingTool
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 1 |
---
|
| 2 |
title: WritingnParaphrasingTool
|
| 3 |
+
emoji: 🏃
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.41.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
app.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Set your Groq API Key
|
| 6 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY") # or hardcode temporarily
|
| 7 |
+
MODEL_NAME = "llama3-70b-8192" # You can also use "mixtral-8x7b-32768" or "gemma-7b-it"
|
| 8 |
+
|
| 9 |
+
# Define task prompts
|
| 10 |
+
TASK_TEMPLATES = {
|
| 11 |
+
"Generate Content": "Write a detailed and engaging piece of content about the following topic:\n\n{input}",
|
| 12 |
+
"Paraphrase": "Paraphrase the following text in a clear and concise way:\n\n{input}",
|
| 13 |
+
"Summarize": "Summarize the following content in a few key points:\n\n{input}",
|
| 14 |
+
"Correct Grammar": "Fix grammatical mistakes and rewrite this text properly:\n\n{input}",
|
| 15 |
+
"Change Tone": "Rewrite the following text in a {tone} tone:\n\n{input}"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def query_groq_model(prompt, temperature=0.7):
|
| 19 |
+
"""Send request to Groq API."""
|
| 20 |
+
url = "https://api.groq.com/openai/v1/chat/completions"
|
| 21 |
+
headers = {
|
| 22 |
+
"Authorization": f"Bearer {GROQ_API_KEY}",
|
| 23 |
+
"Content-Type": "application/json"
|
| 24 |
+
}
|
| 25 |
+
payload = {
|
| 26 |
+
"model": MODEL_NAME,
|
| 27 |
+
"messages": [{"role": "user", "content": prompt}],
|
| 28 |
+
"temperature": temperature,
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 32 |
+
result = response.json()
|
| 33 |
+
return result['choices'][0]['message']['content']
|
| 34 |
+
|
| 35 |
+
def process_text(task, user_input, tone):
|
| 36 |
+
if not user_input.strip():
|
| 37 |
+
return "❗ Please enter some text."
|
| 38 |
+
|
| 39 |
+
if task == "Change Tone":
|
| 40 |
+
prompt = TASK_TEMPLATES[task].format(input=user_input, tone=tone)
|
| 41 |
+
else:
|
| 42 |
+
prompt = TASK_TEMPLATES[task].format(input=user_input)
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
output = query_groq_model(prompt)
|
| 46 |
+
except Exception as e:
|
| 47 |
+
output = f"⚠️ Error: {str(e)}"
|
| 48 |
+
return output
|
| 49 |
+
|
| 50 |
+
# Gradio UI
|
| 51 |
+
with gr.Blocks(title="Content Creation & Paraphrasing Tool") as demo:
|
| 52 |
+
gr.Markdown("## ✍️ Content Creation & Paraphrasing Tool (Open Source + Groq API)")
|
| 53 |
+
|
| 54 |
+
with gr.Row():
|
| 55 |
+
task = gr.Dropdown(
|
| 56 |
+
label="Select Task",
|
| 57 |
+
choices=list(TASK_TEMPLATES.keys()),
|
| 58 |
+
value="Generate Content"
|
| 59 |
+
)
|
| 60 |
+
tone = gr.Dropdown(
|
| 61 |
+
label="Tone (if applicable)",
|
| 62 |
+
choices=["formal", "casual", "professional", "friendly"],
|
| 63 |
+
visible=False
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
user_input = gr.Textbox(label="Input Text or Topic", lines=6, placeholder="Enter your text here...")
|
| 67 |
+
output = gr.Textbox(label="Output", lines=8)
|
| 68 |
+
|
| 69 |
+
task.change(lambda t: gr.update(visible=(t == "Change Tone")), inputs=task, outputs=tone)
|
| 70 |
+
|
| 71 |
+
run_btn = gr.Button("Submit")
|
| 72 |
+
run_btn.click(fn=process_text, inputs=[task, user_input, tone], outputs=output)
|
| 73 |
+
|
| 74 |
+
gr.Markdown("Made with ❤️ using Open Source Models + Groq + Gradio")
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
requests
|