Spaces:
Runtime error
Runtime error
Eerste gradio single model interface werkt
Browse files
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: π
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: green
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Gradio Interface
|
| 3 |
emoji: π
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: green
|
app.py
CHANGED
|
@@ -1,25 +1,39 @@
|
|
| 1 |
import numpy as np
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
def flip_text(x):
|
| 5 |
return x[::-1]
|
| 6 |
|
| 7 |
def flip_image(x):
|
| 8 |
return np.fliplr(x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
with gr.Blocks() as
|
| 11 |
gr.Markdown("My AI interface")
|
| 12 |
with gr.Tab("Single models"):
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
with gr.Tab("Multi models"):
|
| 17 |
with gr.Row():
|
| 18 |
image_input = gr.Image()
|
| 19 |
image_output = gr.Image()
|
| 20 |
image_button = gr.Button("Flip")
|
| 21 |
|
| 22 |
-
text_button.click(flip_text, inputs=text_input, outputs=text_output)
|
| 23 |
image_button.click(flip_image, inputs=image_input, outputs=image_output)
|
|
|
|
| 24 |
|
| 25 |
-
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import gradio as gr
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 4 |
|
| 5 |
def flip_text(x):
|
| 6 |
return x[::-1]
|
| 7 |
|
| 8 |
def flip_image(x):
|
| 9 |
return np.fliplr(x)
|
| 10 |
+
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained("suriya7/bart-finetuned-text-summarization")
|
| 12 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("suriya7/bart-finetuned-text-summarization")
|
| 13 |
+
|
| 14 |
+
def generate_summary(text):
|
| 15 |
+
print(text)
|
| 16 |
+
inputs = tokenizer([text], max_length=1024, return_tensors='pt', truncation=True)
|
| 17 |
+
summary_ids = model.generate(inputs['input_ids'], max_new_tokens=100, do_sample=False)
|
| 18 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 19 |
+
return summary
|
| 20 |
|
| 21 |
+
with gr.Blocks() as main:
|
| 22 |
gr.Markdown("My AI interface")
|
| 23 |
with gr.Tab("Single models"):
|
| 24 |
+
text_to_summarize = gr.Textbox(label="Text to summarize")
|
| 25 |
+
summary_output = gr.Textbox(label="Summary")
|
| 26 |
+
summarize_btn = gr.Button("Summarize")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
with gr.Tab("Multi models"):
|
| 30 |
with gr.Row():
|
| 31 |
image_input = gr.Image()
|
| 32 |
image_output = gr.Image()
|
| 33 |
image_button = gr.Button("Flip")
|
| 34 |
|
| 35 |
+
# text_button.click(flip_text, inputs=text_input, outputs=text_output)
|
| 36 |
image_button.click(flip_image, inputs=image_input, outputs=image_output)
|
| 37 |
+
summarize_btn.click(generate_summary, inputs=text_to_summarize, outputs=summary_output)
|
| 38 |
|
| 39 |
+
main.launch()
|