Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files
README.md
CHANGED
@@ -10,3 +10,7 @@ pinned: false
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
13 |
+
|
14 |
+
Demo: https://huggingface.co/spaces/Kadi-IAM/SimpleWritingHelper
|
15 |
+
|
16 |
+
A simple web app to enhance scientific writing using Large Language Models (LLMs). With features like grammar correction, clarity enhancement, and technical jargon simplification, which helps researchers and academics produce more precise, and readable papers, making scientific communication more efficient and accessible.
|
app.py
CHANGED
@@ -1,3 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import groq
|
@@ -8,6 +15,8 @@ api_key = os.getenv("GROQ_API")
|
|
8 |
|
9 |
|
10 |
def generate_response(prompt):
|
|
|
|
|
11 |
if not prompt:
|
12 |
return "No transcription available. Please try speaking again."
|
13 |
|
@@ -28,12 +37,16 @@ def generate_response(prompt):
|
|
28 |
|
29 |
|
30 |
def writing_improver(text, writing_prompt):
|
|
|
|
|
31 |
combined_propmpt = f"{writing_prompt}\n\nInput:{text}\n\nOutput:"
|
32 |
rephrased_text = generate_response(combined_propmpt)
|
33 |
return rephrased_text
|
34 |
|
35 |
|
36 |
def diff_texts(text1, text2):
|
|
|
|
|
37 |
d = Differ()
|
38 |
return [
|
39 |
(token[2:], token[0] if token[0] != " " else None)
|
@@ -42,11 +55,14 @@ def diff_texts(text1, text2):
|
|
42 |
|
43 |
|
44 |
def text_reviewer(text, review_prompt):
|
|
|
|
|
45 |
combined_propmpt = f"{review_prompt}\n\nInput:{text}\n\nOutput:"
|
46 |
rephrased_text = generate_response(combined_propmpt)
|
47 |
return rephrased_text
|
48 |
|
49 |
|
|
|
50 |
with gr.Blocks() as demo:
|
51 |
gr.Markdown(
|
52 |
"A simple web app to enhance scientific writing π using Large Language Models (LLMs). With features like grammar correction, clarity enhancement, and technical jargon simplification, which helps researchers and academics produce more precise, and readable papers, making scientific communication more efficient and accessible."
|
@@ -55,6 +71,7 @@ with gr.Blocks() as demo:
|
|
55 |
"β οΈ This is designed for research purposes, for best privacy protection, please avoid sharing sensitive or confidential data."
|
56 |
)
|
57 |
|
|
|
58 |
with gr.Tab("Improve writing π"):
|
59 |
with gr.Row():
|
60 |
with gr.Column():
|
@@ -86,12 +103,14 @@ with gr.Blocks() as demo:
|
|
86 |
color_map={"-": "red", "+": "green"},
|
87 |
)
|
88 |
|
|
|
89 |
submit_btn.click(
|
90 |
fn=writing_improver, inputs=[text_input, prompt_input], outputs=output
|
91 |
)
|
92 |
|
93 |
output.change(fn=diff_texts, inputs=[text_input, output], outputs=output_diff)
|
94 |
|
|
|
95 |
gr.Markdown()
|
96 |
gr.Markdown()
|
97 |
gr.Markdown()
|
@@ -115,6 +134,7 @@ with gr.Blocks() as demo:
|
|
115 |
inputs=[text_input, prompt_input],
|
116 |
)
|
117 |
|
|
|
118 |
with gr.Tab("Review Assistant π"):
|
119 |
with gr.Row():
|
120 |
with gr.Column():
|
@@ -142,12 +162,14 @@ with gr.Blocks() as demo:
|
|
142 |
)
|
143 |
review_output = gr.Markdown(label="Reviews")
|
144 |
|
|
|
145 |
review_submit_btn.click(
|
146 |
fn=text_reviewer,
|
147 |
inputs=[review_text_input, review_prompt_input],
|
148 |
outputs=review_output,
|
149 |
)
|
150 |
|
|
|
151 |
gr.Markdown()
|
152 |
gr.Markdown()
|
153 |
gr.Markdown()
|
|
|
1 |
+
"""
|
2 |
+
A simple web app to enhance scientific writing using Large Language Models (LLMs).
|
3 |
+
With features like grammar correction, clarity enhancement, and
|
4 |
+
technical jargon simplification, which helps researchers and academics produce more precise,
|
5 |
+
and readable papers, making scientific communication more efficient and accessible.
|
6 |
+
"""
|
7 |
+
|
8 |
import os
|
9 |
import gradio as gr
|
10 |
import groq
|
|
|
15 |
|
16 |
|
17 |
def generate_response(prompt):
|
18 |
+
"""Get response from LLMs."""
|
19 |
+
|
20 |
if not prompt:
|
21 |
return "No transcription available. Please try speaking again."
|
22 |
|
|
|
37 |
|
38 |
|
39 |
def writing_improver(text, writing_prompt):
|
40 |
+
"""Use LLMs to improve input text."""
|
41 |
+
|
42 |
combined_propmpt = f"{writing_prompt}\n\nInput:{text}\n\nOutput:"
|
43 |
rephrased_text = generate_response(combined_propmpt)
|
44 |
return rephrased_text
|
45 |
|
46 |
|
47 |
def diff_texts(text1, text2):
|
48 |
+
"""Compare two text inputs."""
|
49 |
+
|
50 |
d = Differ()
|
51 |
return [
|
52 |
(token[2:], token[0] if token[0] != " " else None)
|
|
|
55 |
|
56 |
|
57 |
def text_reviewer(text, review_prompt):
|
58 |
+
"""Use LLMs as reviewer for input text."""
|
59 |
+
|
60 |
combined_propmpt = f"{review_prompt}\n\nInput:{text}\n\nOutput:"
|
61 |
rephrased_text = generate_response(combined_propmpt)
|
62 |
return rephrased_text
|
63 |
|
64 |
|
65 |
+
# Gradio UI
|
66 |
with gr.Blocks() as demo:
|
67 |
gr.Markdown(
|
68 |
"A simple web app to enhance scientific writing π using Large Language Models (LLMs). With features like grammar correction, clarity enhancement, and technical jargon simplification, which helps researchers and academics produce more precise, and readable papers, making scientific communication more efficient and accessible."
|
|
|
71 |
"β οΈ This is designed for research purposes, for best privacy protection, please avoid sharing sensitive or confidential data."
|
72 |
)
|
73 |
|
74 |
+
# Sub-app 1. writting improver
|
75 |
with gr.Tab("Improve writing π"):
|
76 |
with gr.Row():
|
77 |
with gr.Column():
|
|
|
103 |
color_map={"-": "red", "+": "green"},
|
104 |
)
|
105 |
|
106 |
+
# Actions
|
107 |
submit_btn.click(
|
108 |
fn=writing_improver, inputs=[text_input, prompt_input], outputs=output
|
109 |
)
|
110 |
|
111 |
output.change(fn=diff_texts, inputs=[text_input, output], outputs=output_diff)
|
112 |
|
113 |
+
# Placeholders
|
114 |
gr.Markdown()
|
115 |
gr.Markdown()
|
116 |
gr.Markdown()
|
|
|
134 |
inputs=[text_input, prompt_input],
|
135 |
)
|
136 |
|
137 |
+
# Sub-app 2. LLM reviewer
|
138 |
with gr.Tab("Review Assistant π"):
|
139 |
with gr.Row():
|
140 |
with gr.Column():
|
|
|
162 |
)
|
163 |
review_output = gr.Markdown(label="Reviews")
|
164 |
|
165 |
+
# Actions
|
166 |
review_submit_btn.click(
|
167 |
fn=text_reviewer,
|
168 |
inputs=[review_text_input, review_prompt_input],
|
169 |
outputs=review_output,
|
170 |
)
|
171 |
|
172 |
+
# Placeholders
|
173 |
gr.Markdown()
|
174 |
gr.Markdown()
|
175 |
gr.Markdown()
|