Eaz123 commited on
Commit
7c97293
·
verified ·
1 Parent(s): 80f4701

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -51
app.py CHANGED
@@ -43,29 +43,6 @@ def paraphrase_text(text, creativity_level=3, tone="neutral"):
43
 
44
  return paraphrased_text, original_count, paraphrased_count
45
 
46
- # Custom CSS for professional look
47
- css = """
48
- .gradio-container {
49
- max-width: 900px !important;
50
- margin: auto !important;
51
- font-family: 'Inter', sans-serif;
52
- }
53
- .contain {
54
- border-radius: 12px !important;
55
- box-shadow: 0 4px 20px rgba(0,0,0,0.1) !important;
56
- }
57
- .dark .input-text, .dark .output-text {
58
- background: #1e1e1e !important;
59
- }
60
- .stats-box {
61
- background: #f8f9fa;
62
- border-radius: 8px;
63
- padding: 12px;
64
- margin-top: 16px;
65
- }
66
- """
67
-
68
- # Comparison table component
69
  def create_comparison(original, paraphrased, orig_count, para_count):
70
  comparison = pd.DataFrame({
71
  "Metric": ["Text", "Word Count"],
@@ -74,59 +51,135 @@ def create_comparison(original, paraphrased, orig_count, para_count):
74
  })
75
  return comparison
76
 
77
- with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
78
- gr.Markdown("""
79
- # <center>Professional AI Paraphraser</center>
80
- <center>Transform your text while preserving meaning with advanced T5 AI</center>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  """)
82
 
83
- with gr.Row():
84
- with gr.Column():
 
 
 
85
  input_text = gr.Textbox(
86
- lines=6,
87
  placeholder="Enter text to paraphrase...",
88
  label="Original Text",
89
- elem_classes=["input-text"]
90
- )
 
91
  with gr.Row():
92
  creativity = gr.Slider(
93
  1, 5, value=3,
94
  label="Creativity Level",
95
- info="1 = Conservative, 5 = Highly Creative"
 
96
  )
97
  tone = gr.Dropdown(
98
  ["neutral", "formal", "casual", "academic"],
99
  value="neutral",
100
- label="Output Tone"
 
101
  )
102
- submit_btn = gr.Button("Paraphrase", variant="primary")
 
 
 
 
 
103
 
104
- with gr.Column():
 
 
105
  output_text = gr.Textbox(
106
- lines=6,
107
  label="Paraphrased Text",
108
  interactive=False,
109
- elem_classes=["output-text"]
110
- )
111
- with gr.Column(elem_classes=["stats-box"]):
112
- gr.Markdown("**Statistics**")
113
- with gr.Row():
114
- orig_count = gr.Number(label="Original Words")
115
- para_count = gr.Number(label="Paraphrased Words")
116
- similarity = gr.Number(label="Similarity Score")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
- # Comparison section
 
119
  with gr.Accordion("Detailed Comparison", open=False):
120
  comparison_table = gr.DataFrame(
121
  headers=["Metric", "Original", "Paraphrased"],
122
  datatype=["str", "str", "str"],
123
- interactive=False
 
124
  )
 
125
 
126
  # Footer
127
- gr.Markdown("""
128
- <div style="text-align: center; margin-top: 20px; color: #666;">
129
- <small>Powered by T5 Transformer | Embeddable in any website</small>
130
  </div>
131
  """)
132
 
@@ -141,6 +194,5 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
141
  outputs=comparison_table
142
  )
143
 
144
- # For embedding
145
  if __name__ == "__main__":
146
  demo.launch()
 
43
 
44
  return paraphrased_text, original_count, paraphrased_count
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  def create_comparison(original, paraphrased, orig_count, para_count):
47
  comparison = pd.DataFrame({
48
  "Metric": ["Text", "Word Count"],
 
51
  })
52
  return comparison
53
 
54
+ # Custom HTML with Tailwind CSS
55
+ custom_html = """
56
+ <script src="https://cdn.tailwindcss.com"></script>
57
+ <style>
58
+ .gradio-container {
59
+ font-family: 'Inter', sans-serif;
60
+ max-width: 100% !important;
61
+ }
62
+ .gradio-interface {
63
+ padding: 0 !important;
64
+ }
65
+ .gradio-input, .gradio-output {
66
+ border: 1px solid #e5e7eb !important;
67
+ border-radius: 0.5rem !important;
68
+ }
69
+ .gradio-input textarea, .gradio-output textarea {
70
+ padding: 1rem !important;
71
+ }
72
+ .gradio-button {
73
+ background-color: #4f46e5 !important;
74
+ color: white !important;
75
+ border-radius: 0.375rem !important;
76
+ padding: 0.5rem 1rem !important;
77
+ font-weight: 500 !important;
78
+ }
79
+ .gradio-button:hover {
80
+ background-color: #4338ca !important;
81
+ }
82
+ .gradio-slider .gradio-slider-handle {
83
+ background: #4f46e5 !important;
84
+ }
85
+ .gradio-slider .gradio-slider-bar {
86
+ background: #c7d2fe !important;
87
+ }
88
+ </style>
89
+ """
90
+
91
+ with gr.Blocks(theme=gr.themes.Base(), css=custom_html) as demo:
92
+ # Header Section
93
+ gr.HTML("""
94
+ <div class="bg-indigo-600 text-white py-6 px-4 rounded-t-lg">
95
+ <div class="max-w-4xl mx-auto text-center">
96
+ <h1 class="text-3xl font-bold mb-2">Professional AI Paraphraser</h1>
97
+ <p class="text-indigo-100">Transform your text while preserving meaning with advanced T5 AI</p>
98
+ </div>
99
+ </div>
100
  """)
101
 
102
+ # Main Content
103
+ with gr.Row().style(equal_height=True):
104
+ with gr.Column(scale=1):
105
+ # Input Section
106
+ gr.HTML("""<div class="p-4 bg-white rounded-lg shadow-sm">""")
107
  input_text = gr.Textbox(
108
+ lines=8,
109
  placeholder="Enter text to paraphrase...",
110
  label="Original Text",
111
+ elem_classes=["border", "rounded-lg", "p-4", "w-full"]
112
+ ).style(container=False)
113
+
114
  with gr.Row():
115
  creativity = gr.Slider(
116
  1, 5, value=3,
117
  label="Creativity Level",
118
+ info="1 = Conservative, 5 = Highly Creative",
119
+ interactive=True
120
  )
121
  tone = gr.Dropdown(
122
  ["neutral", "formal", "casual", "academic"],
123
  value="neutral",
124
+ label="Output Tone",
125
+ interactive=True
126
  )
127
+
128
+ submit_btn = gr.Button(
129
+ "Paraphrase",
130
+ variant="primary"
131
+ ).style(full_width=True)
132
+ gr.HTML("""</div>""")
133
 
134
+ with gr.Column(scale=1):
135
+ # Output Section
136
+ gr.HTML("""<div class="p-4 bg-white rounded-lg shadow-sm h-full">""")
137
  output_text = gr.Textbox(
138
+ lines=8,
139
  label="Paraphrased Text",
140
  interactive=False,
141
+ elem_classes=["border", "rounded-lg", "p-4", "w-full"]
142
+ ).style(container=False)
143
+
144
+ # Stats Section
145
+ gr.HTML("""
146
+ <div class="mt-4 p-4 bg-gray-50 rounded-lg">
147
+ <h3 class="font-medium text-gray-900 mb-3">Statistics</h3>
148
+ <div class="grid grid-cols-3 gap-4">
149
+ """)
150
+
151
+ with gr.Row():
152
+ orig_count = gr.Number(
153
+ label="Original Words",
154
+ interactive=False
155
+ ).style(container=False)
156
+ para_count = gr.Number(
157
+ label="Paraphrased Words",
158
+ interactive=False
159
+ ).style(container=False)
160
+ similarity = gr.Number(
161
+ label="Similarity Score",
162
+ interactive=False,
163
+ visible=False # Placeholder for future feature
164
+ ).style(container=False)
165
+
166
+ gr.HTML("""</div></div></div>""")
167
 
168
+ # Comparison Section
169
+ gr.HTML("""<div class="mt-4 p-4 bg-white rounded-lg shadow-sm">""")
170
  with gr.Accordion("Detailed Comparison", open=False):
171
  comparison_table = gr.DataFrame(
172
  headers=["Metric", "Original", "Paraphrased"],
173
  datatype=["str", "str", "str"],
174
+ interactive=False,
175
+ elem_classes=["w-full"]
176
  )
177
+ gr.HTML("""</div>""")
178
 
179
  # Footer
180
+ gr.HTML("""
181
+ <div class="mt-6 py-4 text-center text-gray-500 text-sm">
182
+ <p>Powered by T5 Transformer | Embeddable in any website</p>
183
  </div>
184
  """)
185
 
 
194
  outputs=comparison_table
195
  )
196
 
 
197
  if __name__ == "__main__":
198
  demo.launch()