Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from utils.summarizer import summarize_text
|
| 3 |
+
from utils.translator import translate_to_french
|
| 4 |
+
|
| 5 |
+
# Load external CSS
|
| 6 |
+
with open("style.css", "r") as f:
|
| 7 |
+
custom_css = f.read()
|
| 8 |
+
|
| 9 |
+
def process_text(task, text):
|
| 10 |
+
if task == "Summarization":
|
| 11 |
+
return summarize_text(text)
|
| 12 |
+
elif task == "Translate to French":
|
| 13 |
+
return translate_to_french(text)
|
| 14 |
+
else:
|
| 15 |
+
return "Invalid task selected."
|
| 16 |
+
|
| 17 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 18 |
+
gr.Markdown("### Summarize or Translate long-form text using Hugging Face Transformers and Gradio")
|
| 19 |
+
|
| 20 |
+
with gr.Row():
|
| 21 |
+
with gr.Column(elem_classes="card"):
|
| 22 |
+
task = gr.Dropdown(
|
| 23 |
+
["Summarization", "Translate to French"],
|
| 24 |
+
label="Task",
|
| 25 |
+
elem_classes="dropdown"
|
| 26 |
+
)
|
| 27 |
+
input_text = gr.Textbox(
|
| 28 |
+
lines=12,
|
| 29 |
+
placeholder="Enter your text here...",
|
| 30 |
+
label="Input Text",
|
| 31 |
+
elem_classes="textbox"
|
| 32 |
+
)
|
| 33 |
+
submit_btn = gr.Button("Submit", elem_classes="submit-button")
|
| 34 |
+
with gr.Column(elem_classes="card"):
|
| 35 |
+
output = gr.Textbox(label="Result", elem_classes="output")
|
| 36 |
+
|
| 37 |
+
submit_btn.click(fn=process_text, inputs=[task, input_text], outputs=output)
|
| 38 |
+
|
| 39 |
+
demo.launch()
|