Spaces:
Runtime error
Runtime error
Update app.py with potential fix
#1
by
AdamOswald1 - opened
app.py
CHANGED
|
@@ -1,46 +1,62 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
-
#Importing dependancies
|
| 3 |
from styleformer import Styleformer
|
| 4 |
import gradio as gr
|
| 5 |
import torch
|
| 6 |
import warnings
|
|
|
|
| 7 |
warnings.filterwarnings("ignore")
|
| 8 |
|
|
|
|
| 9 |
def set_seed(seed):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
set_seed(1234)
|
| 15 |
|
| 16 |
-
#Casual-Formal
|
| 17 |
sf_0 = Styleformer(style=0)
|
| 18 |
|
| 19 |
-
#Formal-Casual
|
| 20 |
sf_1 = Styleformer(style=1)
|
| 21 |
|
| 22 |
-
#Active-Passive
|
| 23 |
sf_2 = Styleformer(style=2)
|
| 24 |
|
| 25 |
-
#Passive-Active
|
| 26 |
sf_3 = Styleformer(style=3)
|
| 27 |
|
|
|
|
| 28 |
def func(text, tone):
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
app_description = "This model transforms the tone of text, from formal to informal, from Active to Passive. Choose your option below."
|
| 42 |
app_title = "Tone Transfer"
|
| 43 |
|
| 44 |
-
app = gr.Interface(
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
+
# Importing dependancies
|
| 3 |
from styleformer import Styleformer
|
| 4 |
import gradio as gr
|
| 5 |
import torch
|
| 6 |
import warnings
|
| 7 |
+
|
| 8 |
warnings.filterwarnings("ignore")
|
| 9 |
|
| 10 |
+
|
| 11 |
def set_seed(seed):
|
| 12 |
+
torch.manual_seed(seed)
|
| 13 |
+
if torch.cuda.is_available():
|
| 14 |
+
torch.cuda.manual_seed_all(seed)
|
| 15 |
+
|
| 16 |
|
| 17 |
set_seed(1234)
|
| 18 |
|
| 19 |
+
# Casual-Formal
|
| 20 |
sf_0 = Styleformer(style=0)
|
| 21 |
|
| 22 |
+
# Formal-Casual
|
| 23 |
sf_1 = Styleformer(style=1)
|
| 24 |
|
| 25 |
+
# Active-Passive
|
| 26 |
sf_2 = Styleformer(style=2)
|
| 27 |
|
| 28 |
+
# Passive-Active
|
| 29 |
sf_3 = Styleformer(style=3)
|
| 30 |
|
| 31 |
+
|
| 32 |
def func(text, tone):
|
| 33 |
+
if tone == "Casual-Formal":
|
| 34 |
+
return sf_0.transfer(text)
|
| 35 |
+
if tone == "Formal-Casual":
|
| 36 |
+
return sf_1.transfer(text)
|
| 37 |
+
if tone == "Active-Passive":
|
| 38 |
+
return sf_2.transfer(text)
|
| 39 |
+
if tone == "Passive-Active":
|
| 40 |
+
return sf_3.transfer(text)
|
| 41 |
+
else:
|
| 42 |
+
return "No available Transfers😭"
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# Initalizing Gradio App
|
| 46 |
app_description = "This model transforms the tone of text, from formal to informal, from Active to Passive. Choose your option below."
|
| 47 |
app_title = "Tone Transfer"
|
| 48 |
|
| 49 |
+
app = gr.Interface(
|
| 50 |
+
func,
|
| 51 |
+
[
|
| 52 |
+
"text",
|
| 53 |
+
gr.inputs.Radio(
|
| 54 |
+
["Casual-Formal", "Formal-Casual", "Active-Passive", "Passive-Active"]
|
| 55 |
+
),
|
| 56 |
+
],
|
| 57 |
+
"text",
|
| 58 |
+
description=app_description,
|
| 59 |
+
title=app_title,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
app.launch()
|